]> granicus.if.org Git - php/commitdiff
Fix realpath not to die on non-existing files (bug #5790)
authorStanislav Malyshev <stas@php.net>
Thu, 27 Jul 2000 13:48:50 +0000 (13:48 +0000)
committerStanislav Malyshev <stas@php.net>
Thu, 27 Jul 2000 13:48:50 +0000 (13:48 +0000)
Thanks to china@thewrittenword.com

main/php_realpath.c

index 26a9359e086ea2d9de5a0746041cac32f96ebbc8..339eb2eb8f23822229a667bd15b21f47625602f7 100644 (file)
@@ -251,15 +251,18 @@ char *php_realpath(char *path, char resolved_path []) {
        }
 
        /* Check if the resolved path is a directory */
-       if (V_STAT(path_construction, &filestat) != 0) return NULL;
-       if (S_ISDIR(filestat.st_mode)) {
-               /* It's a directory, append a / if needed */
-               if (*(writepos-1) != '/') {
-                       /* Check for overflow */
-                       if ((strlen(workpos) + 2) >= MAXPATHLEN) return NULL;
-
-                       *writepos++ = '/';
-                       *writepos = 0;
+       if (V_STAT(path_construction, &filestat) != 0) {
+               if (errno != ENOENT) return NULL;
+       } else {
+               if (S_ISDIR(filestat.st_mode)) {
+                       /* It's a directory, append a / if needed */
+                       if (*(writepos-1) != '/') {
+                               /* C    heck for overflow */
+                               if ((strlen(workpos) + 2) >= MAXPATHLEN) return NULL;
+                               
+                               *writepos++ = '/';
+                               *writepos = 0;
+                       }
                }
        }