Fixed bug in verifyPath() that was breaking PHYSFS_setSaneConfig() and other
authorRyan C. Gordon <icculus@icculus.org>
Sat, 20 Aug 2005 04:46:25 +0000
changeset 746 88780f7156d3
parent 745 df04959950eb
child 747 3da194b12f43
Fixed bug in verifyPath() that was breaking PHYSFS_setSaneConfig() and other
corner cases.
CHANGELOG
physfs.c
--- a/CHANGELOG	Mon Jul 25 01:38:07 2005 +0000
+++ b/CHANGELOG	Sat Aug 20 04:46:25 2005 +0000
@@ -2,6 +2,8 @@
  * CHANGELOG.
  */
 
+08202005 - Fixed bug in verifyPath() that was breaking PHYSFS_setSaneConfig()
+           and other corner cases.
 07242005 - Patched to compile on BeOS.
 07232005 - Fixed bug in zip archiver (thanks, Jörg Walter!).
            More minor OS/2 tweaks. Updated zlib to 1.2.3, which properly
--- a/physfs.c	Mon Jul 25 01:38:07 2005 +0000
+++ b/physfs.c	Sat Aug 20 04:46:25 2005 +0000
@@ -1107,7 +1107,7 @@
 
     BAIL_IF_MACRO(!initialized, ERR_NOT_INITIALIZED, 0);
 
-        /* set write dir... */
+    /* set write dir... */
     str = (char *) allocator.Malloc(
             strlen(userdir) + (strlen(organization) * 2) +
             (strlen(appName) * 2) + (strlen(dirsep) * 3) + 2);
@@ -1325,12 +1325,14 @@
     {
         while (1)
         {
+            int rc = 0;
             end = strchr(start, '/');
-            if (end != NULL)
-                *end = '\0';
 
-            if (h->funcs->isSymLink(h->opaque, fname, &retval))
-                BAIL_MACRO(ERR_SYMLINK_DISALLOWED, 0);   /* insecure. */
+            if (end != NULL) *end = '\0';
+            rc = h->funcs->isSymLink(h->opaque, fname, &retval);
+            if (end != NULL) *end = '/';
+
+            BAIL_IF_MACRO(rc, ERR_SYMLINK_DISALLOWED, 0);   /* insecure. */
 
             /* break out early if path element is missing. */
             if (!retval)
@@ -1348,7 +1350,6 @@
             if (end == NULL)
                 break;
 
-            *end = '/';
             start = end + 1;
         } /* while */
     } /* if */