PHP 4.0 Bug #5790: touch on a non-existent file does not work

From: Date: Wed, 26 Jul 2000 04:34:22 +0000
Subject: PHP 4.0 Bug #5790: touch on a non-existent file does not work
Groups: php.dev 
Request: Send a blank email to php-dev+get-26201@lists.php.net to get a copy of this message
From: china@thewrittenword.com Operating system: FreeBSD 3.4 PHP version: 4.0.1pl2 PHP Bug Type: Misbehaving function Bug description: touch on a non-existent file does not work 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; + } } }

« previous php.dev (#26201) next »