PHP 4.0 Bug #3697: open_basedir prevents creating files with fopen
| From: | djm at web dot us dot uu dot net | Date: | Thu, 02 Mar 2000 05:57:16 +0000 |
| Subject: | PHP 4.0 Bug #3697: open_basedir prevents creating files with fopen | ||
| Groups: | php.dev | ||
| Request: | Send a blank email to php-dev+get-16255@lists.php.net to get a copy of this message | ||
From: djm@web.us.uu.net
Operating system: BSD/OS 4.0.1
PHP version: 4.0 Beta 4 Patch Level 1
PHP Bug Type: Misbehaving function
Bug description: open_basedir prevents creating files with fopen
I have open_basedir set and I am trying to create a file under that directory using
$fp = fopen("cities.wddx", "w");
However, it fails:
<b>Warning</b>: open_basedir restriction in effect. File is in wrong directory in
<b>/homes/web/testtest5/html/serialize.php</b> on line <b>17</b><br>
Adding some more warning messages to the PHP source code reveals that the stat() toward the end of
php_realpath() is the culprit. Of course it can't stat the file if I'm trying to create
it. A suggested fix:
Index: php_realpath.c
@@ -251,12 +258,25 @@
}
/* Check if the resolved path is a directory */
- if (stat(path_construction, &filestat) != 0) return NULL;
+ if (stat(path_construction, &filestat) != 0) {
+ /* It doesn't exist yet; check the directory it's in instead. */
+ while (*--writepos != '/' && writepos > path_construction)
+ ;
+ *writepos = 0;
+ if (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 */