You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@httpd.apache.org by W G Stoddard <wg...@us.ibm.com> on 1998/06/23 15:49:12 UTC

[PATCH] UPDATE - Win32 fix trailing slashes, PR's 2274 & 234

The last patch had a problem handling <Directory />. Here is an updated patch.

Thanks,
Bill (Biru) Stoddard
wgstodda@us.ibm.com

*** util_win32.c.orig Fri Jun 19 20:09:37 1998
--- util_win32.c Fri Jun 19 20:07:34 1998
***************
*** 4,16 ****

  #include "httpd.h"

! static void sub_canonical_filename(char *szCanon, unsigned nCanon, const char
*szFile)
  {
      char buf[HUGE_STRING_LEN];
      int n;
      char *szFilePart;
      WIN32_FIND_DATA d;
      HANDLE h;

      n = GetFullPathName(szFile, sizeof buf, buf, &szFilePart);
      ap_assert(n);
--- 4,47 ----

  #include "httpd.h"

! /*
!  *  This routine will count the number of '\'s at the end of the given string.
!  */
! static int num_tail_slashes(char *szFile)
! {
!     int iSlashCount = 0;
!     int i;
!
!     i = strlen(szFile)-1;
!
!     while ((i>=0) && (szFile[i] == '\\')) {
!         i--;
!         iSlashCount++;
!     }
!     return iSlashCount;
! }
!
! static void sub_canonical_filename(char *szCanon, unsigned nCanon, char
*szFile)
  {
      char buf[HUGE_STRING_LEN];
      int n;
      char *szFilePart;
      WIN32_FIND_DATA d;
      HANDLE h;
+     int iInSlashCount, iOutSlashCount;
+
+     /*
+      *  We don't want to use a file name that has a trailing \ because it
+      *  breaks this routine and GetFullPathName doesn't like it either.
+      *  We count off the slahes and save that number so we will add the
+      *  slashes back before returning from this routine.
+      */
+     iInSlashCount = num_tail_slashes(szFile);
+
+     if (iInSlashCount && (*(szFile + 1) != '\0'))
+         szFile[strlen(szFile)-iInSlashCount] = '\0';
+     else
+        iInSlashCount = 0;

      n = GetFullPathName(szFile, sizeof buf, buf, &szFilePart);
      ap_assert(n);
***************
*** 48,80 ****
    if(*s == '\\')
        *s='/';
   }
-         return;
-     }
-     if (szFilePart != buf+3) {
-         char b2[_MAX_PATH];
-         ap_assert(szFilePart > buf+3);
-
-         szFilePart[-1]='\0';
-         sub_canonical_filename(b2, sizeof b2, buf);
-
-  ap_assert(strlen(b2)+1 < nCanon);
-         strcpy(szCanon, b2);
-         strcat(szCanon, "/");
-     }
-     else {
-  ap_assert(strlen(buf) < nCanon);
-         strcpy(szCanon, buf);
-         szCanon[2] = '/';
-         szCanon[3] = '\0';
-     }
-     if (h == INVALID_HANDLE_VALUE) {
-  ap_assert(strlen(szCanon)+strlen(szFilePart) < nCanon);
-         strcat(szCanon, szFilePart);
      }
      else {
!  ap_assert(strlen(szCanon)+strlen(d.cFileName) < nCanon);
!         strlwr(d.cFileName);
!         strcat(szCanon, d.cFileName);
      }
  }

--- 79,123 ----
    if(*s == '\\')
        *s='/';
   }
      }
      else {
!         if (szFilePart != buf+3) {
!             char b2[_MAX_PATH];
!             ap_assert(szFilePart > buf+3);
!
!             szFilePart[-1]='\0';
!             sub_canonical_filename(b2, sizeof b2, buf);
!
!             ap_assert(strlen(b2)+1 < nCanon);
!             strcpy(szCanon, b2);
!             strcat(szCanon, "/");
!         }
!         else {
!             ap_assert(strlen(buf) < nCanon);
!             strcpy(szCanon, buf);
!             szCanon[2] = '/';
!             szCanon[3] = '\0';
!         }
!         if (h == INVALID_HANDLE_VALUE) {
!             ap_assert(strlen(szCanon)+strlen(szFilePart) < nCanon);
!             strcat(szCanon, szFilePart);
!         }
!         else {
!             ap_assert(strlen(szCanon)+strlen(d.cFileName) < nCanon);
!             strlwr(d.cFileName);
!             strcat(szCanon, d.cFileName);
!         }
!     }
!
!     /*
!      *  If this filename had any slashes when we came in, then
!      *  add those slashes back here.
!      */
!     if (iInSlashCount) {
!         int i;
!         iOutSlashCount = num_tail_slashes(szCanon);
!         for (i=iOutSlashCount; i < iInSlashCount; i++)
!             strcat(szCanon, "/");
      }
  }



cat  > /dev/null

Users of the Apache webserver are hereby granted a non-exclusive, irrevocable,
world-wide, royalty-free, non-transferable license to use, execute, prepare
derivative works of, and distribute (internally and externally, and including
derivative works) the code accompanying this license as part of, and integrated
into the Apache webserver.

This code is provided "AS IS" WITHOUT WARRANTY OF ANY KIND EITHER EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTY OF MERCHANTABILITY
AND FITNESS FOR A PARTICULAR PURPOSE.  THE ENTIRE RISK ARISING OUT OF THE USE
OR PERFORMANCE OF THIS CODE REMAINS WITH USERS OF THE APACHE WEBSERVER.

I represent and warrant that I am legally entitled to grant the above license.

Ctrl-D

Re: [PATCH] UPDATE - Win32 fix trailing slashes, PR's 2274 & 234

Posted by Ben Laurie <be...@algroup.co.uk>.
W G Stoddard wrote:
> 
> The last patch had a problem handling <Directory />. Here is an updated patch.

I'm still not convinced about this:

a) This is supposed to produce a canonical filename, so why are we
carefully preserving non-canonical clagger?

b) Surely there is no point in doing this for every component, which is
what happens if you have it in sub_canonical_filename.

Cheers,

Ben.

-- 
Ben Laurie            |Phone: +44 (181) 735 0686| Apache Group member
Freelance Consultant  |Fax:   +44 (181) 735 0689|http://www.apache.org/
and Technical Director|Email: ben@algroup.co.uk |
A.L. Digital Ltd,     |Apache-SSL author     http://www.apache-ssl.org/
London, England.      |"Apache: TDG" http://www.ora.com/catalog/apache/

WE'RE RECRUITING! http://www.aldigital.co.uk/recruit/