#31570 [NEW]: PHP unable to resolve relative paths in __destruct() upon unloading page
| From: | twadzilla at gmail dot com | Date: | Sun, 16 Jan 2005 13:43:13 +0000 |
| Subject: | #31570 [NEW]: PHP unable to resolve relative paths in __destruct() upon unloading page | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-72242@lists.php.net to get a copy of this message | ||
From: twadzilla at gmail dot com
Operating system: Redhat 9
PHP version: 5CVS-2005-01-16 (dev)
PHP Bug Type: Zend Engine 2 problem
Bug description: PHP unable to resolve relative paths in __destruct() upon unloading page
Description:
------------
PHP generates a warning inside a class destructor when you try to read a
file, because apparently it cannot resolve relative paths by the time when
the destructor is called for referenced objects.
When the open_basedir config is commented out, only the "include"
directive resolves the relative path; the other file-reading methods
fail.
When open_basedir is in effect, it causes all the methods to fail,
including the "include" directive.
The following issue is demonstrated at:
http://test.kneetoe.com/foo.php
http://test.kneetoe.com/foo.php.txt
(alternatively with more checks):
http://test.kneetoe.com/foo2.php
http://test.kneetoe.com/foo2.php.txt
I recommend that class destructors get executed before the ability to
resolve relative paths gets unloaded.
http://test.kneetoe.com/phpinfo.php
Reproduce code:
---------------
[httpd.conf]:
php_admin_value open_basedir /home/test/www
[/home/test/www/bar.html]:
Bar!
[/home/test/www/foo.php]:
class Foo {
function __destruct() {
$relative = 'bar.html';
$absolute = "/home/test/www/$abs";
echo "Absolute 'include': ";
include $absolute;
echo "Relative 'include': ";
include $relative;
echo "Absolute 'readfile': ";
readfile($absolute);
echo "Relative 'readfile': ";
readfile($relative);
}
}
print "<h2>Non-referenced (immediate destruction):</h2>";
new Foo;
print "<h2>Referenced (delayed destruction):</h2>";
$a = new Foo;
Expected result:
----------------
Non-referenced (immediate destruction):
Absolute 'include': Bar!
Relative 'include': Bar!
Absolute 'readfile': Bar!
Relative 'readfile': Bar!
Referenced (delayed destruction):
Absolute 'include': Bar!
Relative 'include': Bar!
Absolute 'readfile': Bar!
Relative 'readfile': Bar!
Actual result:
--------------
[[[open_basedir commented out]]]:
Non-referenced (immediate destruction):
Absolute 'include': Bar!
Relative 'include': Bar!
Absolute 'readfile': Bar!
Relative 'readfile': Bar!
Referenced (delayed destruction):
Absolute 'include': Bar!
Relative 'include': Bar!
Absolute 'readfile': Bar!
Relative 'readfile':
Warning: readfile(bar.html) [function.readfile]: failed to open stream:
No such file or directory in /home/test/www/foo.php on line 19
[[[open_basedir in effect]]]:
Non-referenced (immediate destruction):
Absolute 'include': Bar!
Relative 'include': Bar!
Absolute 'readfile': Bar!
Relative 'readfile': Bar!
Referenced (delayed destruction):
Absolute 'include': Bar!
Relative 'include':
Warning: Foo::__destruct() [function.--destruct]: open_basedir
restriction in effect. File(./bar.html) is not within the allowed path(s):
(/home/test/www) in /home/test/www/foo.php on line 13
Warning: Foo::__destruct(bar.html) [function.--destruct]: failed to open
stream: Operation not permitted in /home/test/www/foo.php on line 13
Warning: Foo::__destruct() [function.include]: Failed opening 'bar.html'
for inclusion (include_path='.:/usr/local/lib/php') in
/home/test/www/foo.php on line 13
Absolute 'readfile': Bar!
Relative 'readfile':
Warning: readfile() [function.readfile]: open_basedir restriction in
effect. File(bar.html) is not within the allowed path(s): (/home/test/www)
in /home/test/www/foo.php on line 19
Warning: readfile(bar.html) [function.readfile]: failed to open stream:
Operation not permitted in /home/test/www/foo.php on line 19
--
Edit bug report at http://bugs.php.net/?id=31570&edit=1
--
Try a CVS snapshot (php4): http://bugs.php.net/fix.php?id=31570&r=trysnapshot4
Try a CVS snapshot (php5.0): http://bugs.php.net/fix.php?id=31570&r=trysnapshot50
Try a CVS snapshot (php5.1): http://bugs.php.net/fix.php?id=31570&r=trysnapshot51
Fixed in CVS: http://bugs.php.net/fix.php?id=31570&r=fixedcvs
Fixed in release: http://bugs.php.net/fix.php?id=31570&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=31570&r=needtrace
Need Reproduce Script: http://bugs.php.net/fix.php?id=31570&r=needscript
Try newer version: http://bugs.php.net/fix.php?id=31570&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=31570&r=support
Expected behavior: http://bugs.php.net/fix.php?id=31570&r=notwrong
Not enough info: http://bugs.php.net/fix.php?id=31570&r=notenoughinfo
Submitted twice: http://bugs.php.net/fix.php?id=31570&r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=31570&r=globals
PHP 3 support discontinued: http://bugs.php.net/fix.php?id=31570&r=php3
Daylight Savings: http://bugs.php.net/fix.php?id=31570&r=dst
IIS Stability: http://bugs.php.net/fix.php?id=31570&r=isapi
Install GNU Sed: http://bugs.php.net/fix.php?id=31570&r=gnused
Floating point limitations: http://bugs.php.net/fix.php?id=31570&r=float
No Zend Extensions: http://bugs.php.net/fix.php?id=31570&r=nozend
MySQL Configuration Error: http://bugs.php.net/fix.php?id=31570&r=mysqlcfg