file_exists() warns of open_basedir restriction on non-existent file
| Bug #41518 | file_exists() warns of open_basedir restriction on non-existent file | |||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Submitted: | 2007-05-28 13:38 UTC | Modified: | 2007-07-03 07:05 UTC |
|
||||||||||
| From: | ruben dot willmes at emil2001 dot de | Assigned: | tony2001 (profile) | |||||||||||
| Status: | Closed | Package: | Safe Mode/open_basedir | |||||||||||
| PHP Version: | 5.2.2 | OS: | Linux | |||||||||||
| Private report: | No | CVE-ID: | None | |||||||||||
[2007-05-28 13:38 UTC] ruben dot willmes at emil2001 dot de
Description: ------------ If open_basedir is active, file_exists(), as well as is_dir() and is_file(), throw an open_basedir warning if you check a non-existent file in a directory mentioned in the open_basedir configuration. The directories used in this case aren't symlinks. The following example describes the situation with is_file(), but you'll get the same result with is_dir() and file_exists(). For a reference please see Bug #24313 http://bugs.php.net/bug.php?id=24313 Sorry if this is a dub, but i didn't found any bugs referring to the actual PHP version Reproduce code: --------------- if (is_file('/var/www/localhost/htdocs/index.phph')) { print "File exists"; } else { print "File does not exist"; } Expected result: ---------------- is_file should return a FALSE and you should read "File does not exist". Actual result: -------------- In addition to "File does not exist", you'll get a warning that open_basedir restriction is in effect: Warning: is_file() [function.is-file]: open_basedir restriction in effect. File(/var/www/localhost/htdocs/index.phph) is not within the allowed path(s): (/var/www/localhost/htdocs/) in /var/www/localhost/ htdocs/check.php on line 3
Patches
Pull Requests
History
AllCommentsChangesGit/SVN commits
[2007-05-28 22:05 UTC] xeo2001 at yahoo dot com
I have to disagree with you. I'v set a open base dir as /www/home/user and when i open (the by you produced code) in /www/home/user/test.php as: <? if (is_file('/www/home/user/index.phph')) { print "File exists"; }else { print "File does not exist"; } ?> I just get the text "File does not exist". I think you got a problem in your server configuration? Running system(s): Debian 4.1 Apache 1.3.37 Php 4.4.7[2007-05-28 22:09 UTC] xeo2001 at yahoo dot com
[2007-05-29 06:58 UTC] ruben dot willmes at emil2001 dot de
[2007-05-29 20:39 UTC] tony2001@php.net
[2007-05-30 20:20 UTC] ruben dot willmes at emil2001 dot de
[2007-05-31 11:06 UTC] tony2001@php.net
I don't think I get what you're talking about: # ls -l /tmp/nosuch ls: cannot access /tmp/nosuch: No such file or directory #php -d open_basedir=/tmp -r 'var_dump(file_exists("/tmp/nosuch"));' bool(false) No warning whatsoever.[2007-05-31 12:40 UTC] ruben dot willmes at emil2001 dot de
Your example is correct, that does work, but what if you change the following: Instead of #php -d open_basedir=/tmp -r 'var_dump(file_exists("/tmp/nosuch"));' try #php -d open_basedir=/tmp/ -r 'var_dump(file_exists("/tmp/nosuch"));' Notice the slash behind "open_basedir=/tmp/". With that you get Warning: file_exists(): open_basedir restriction in effect. File(/tmp/ nosuch) is not within the allowed path(s): (/tmp/) in Command line code on line 1 bool(false)[2007-06-01 00:02 UTC] phpbugs at thequod dot de
[2007-06-18 18:41 UTC] paul at moonkhan dot org
@Ruben Running PHP 5.2.3 on Redhat Enterprise Linux 4 I get the following: #php -d open_basedir=/tmp -r 'var_dump(file_exists("/tmp/nosuch"));' bool(false) But if I switch /tmp to /tmp/ (ie, with trailing slash): #php -d open_basedir=/tmp/ -r 'var_dump(file_exists("/tmp/nosuch"));' PHP Warning: file_exists(): open_basedir restriction in effect. File(/tmp/nosuch) is not within the allowed path(s): (/tmp/) in Command line code on line 1 Warning: file_exists(): open_basedir restriction in effect. File(/tmp/nosuch) is not within the allowed path(s): (/tmp/) in Command line code on line 1 bool(false) We can eliminate this problem in our environment if we remove the trailing slashes from our open_basedir settings but that's not how open_basedir was intended to work, since trailing slashes prevent "wildcarding". For example, "/tmp" matches "/tmpfoo" and "/tmpbar" but "/tmp/" should only match, well, /tmp/. -Paul[2007-07-03 07:05 UTC] tony2001@php.net