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/19 13:08:54 UTC

[PATCH] Win32 fix trailing slashes, PR's 2274 & 2348

Ref PR's 2274 & 2348

This patch fixes the problems reported in 2274 & 2348, as best as I can tell.
There are probably a few more like this still in hiding. Many of the functions
in util_win32.c need to be rewritten to handle arbitrary length strings, IMHO.
Another day...

Bill Stoddard
wgstodda@us.ibm.com


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.


*** util_win32.c.orig Thu Jun 18 13:25:31 1998
--- util_win32.c Thu Jun 18 13:27:41 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,45 ----

  #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[strlen(szFile)-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);
      }
  }

--- 77,121 ----
    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, "/");
      }
  }



Re: [PATCH] Win32 fix trailing slashes, PR's 2274 & 2348

Posted by Ben Laurie <be...@algroup.co.uk>.
W G Stoddard wrote:
> 
> Ref PR's 2274 & 2348
> 
> This patch fixes the problems reported in 2274 & 2348, as best as I can tell.
> There are probably a few more like this still in hiding. Many of the functions
> in util_win32.c need to be rewritten to handle arbitrary length strings, IMHO.
> Another day...

Surely there can only be trailing slashes in the first iteration, so
this patch belongs in os_canonical_filename, rather than
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/