php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #5790 touch on a non-existent file does not work
Submitted: 2000-07-26 06:34 UTC Modified: 2005-01-31 23:05 UTC
From: china at thewrittenword dot com Assigned:
Status: Closed Package: Safe Mode/open_basedir
PHP Version: 4.0.1pl2 OS: FreeBSD 3.4
Private report: No CVE-ID: None
 [2000-07-26 06:34 UTC] china at thewrittenword dot com
If safe_mode is on and touch is executed on a file *inside* the open_basedir directory, the file will *not* get created. This is because php_realpath() in main/php_realpath.c checks for the existence of the file before returning. If the file does not exist, NULL is returned, in which case the calling function exits with an error, causing touch to end with an error. Why should php_realpath care if the file it ends up with exists? It's sole purpose is to give the canonical path, regardless of whether it exists or not. So, the following patch fixes this problem:

--- main/php_realpath.c.orig    Tue Jul 25 22:50:08 2000
+++ main/php_realpath.c Tue Jul 25 23:28:02 2000
@@ -251,15 +251,18 @@
        }
 
        /* 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;
+       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) != '/') {
+                               /* Check for overflow */
+                               if ((strlen(workpos) + 2) >= MAXPATHLEN) return NULL;
 
-                       *writepos++ = '/';
-                       *writepos = 0;
+                               *writepos++ = '/';
+                               *writepos = 0;
+                       }
                }
        }

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2000-07-27 15:47 UTC] stas@php.net
fixed in CVS, please check.
 
PHP Copyright © 2001-2020 The PHP Group
All rights reserved.
Last updated: Mon Jan 27 09:01:25 2020 UTC