From: Ilia Alshanetsky Date: Tue, 24 Jun 2003 13:44:57 +0000 (+0000) Subject: MFH: Fixed bug #24313 (file_exist() warning on non-existent files when X-Git-Tag: php-4.3.3RC2~257 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=557fd9b7a3bb73c056319887da844866bb932f30;p=php MFH: Fixed bug #24313 (file_exist() warning on non-existent files when open_basedir is used). --- diff --git a/NEWS b/NEWS index f0c16a3c20..7e60eeaaf4 100644 --- a/NEWS +++ b/NEWS @@ -2,6 +2,8 @@ PHP 4 NEWS ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| 26 Jun 2003, Version 4.3.3RC2 +- Fixed bug #24313 (file_exist() warning on non-existent files + when open_basedir is used). (Ilia) - Fixed bug #24284 (Fixed memory leak inside pg_ping()). (Ilia) 19 Jun 2003, Version 4.3.3RC1 diff --git a/ext/standard/filestat.c b/ext/standard/filestat.c index a5d1899dcf..94580f6fdd 100644 --- a/ext/standard/filestat.c +++ b/ext/standard/filestat.c @@ -572,7 +572,7 @@ static void php_stat(const char *filename, php_stat_len filename_length, int typ RETURN_FALSE; } - if (php_check_open_basedir(filename TSRMLS_CC)) { + if (php_check_open_basedir_ex(filename, IS_EXISTS_CHECK(type) ? 0 : 1 TSRMLS_CC)) { RETURN_FALSE; } diff --git a/ext/standard/tests/file/bug24313.phpt b/ext/standard/tests/file/bug24313.phpt new file mode 100644 index 0000000000..67b7cf8dd8 --- /dev/null +++ b/ext/standard/tests/file/bug24313.phpt @@ -0,0 +1,10 @@ +--TEST-- +Bug #24313: file_exists() warning on non-existant files when is open_basedir enabled +--INI-- +open_basedir=/tmp +--FILE-- + +--EXPECT-- +bool(false) diff --git a/main/fopen_wrappers.c b/main/fopen_wrappers.c index 6f673f7bc0..f9ab69a6ac 100644 --- a/main/fopen_wrappers.c +++ b/main/fopen_wrappers.c @@ -163,9 +163,14 @@ PHPAPI int php_check_specific_open_basedir(const char *basedir, const char *path } /* }}} */ +PHPAPI int php_check_open_basedir(const char *path TSRMLS_DC) +{ + return php_check_open_basedir_ex(path, 1 TSRMLS_DC); +} + /* {{{ php_check_open_basedir */ -PHPAPI int php_check_open_basedir(const char *path TSRMLS_DC) +PHPAPI int php_check_open_basedir_ex(const char *path, int warn TSRMLS_DC) { /* Only check when open_basedir is available */ if (PG(open_basedir) && *PG(open_basedir)) { @@ -191,8 +196,10 @@ PHPAPI int php_check_open_basedir(const char *path TSRMLS_DC) ptr = end; } - php_error_docref(NULL TSRMLS_CC, E_WARNING, - "open_basedir restriction in effect. File(%s) is not within the allowed path(s): (%s)", path, PG(open_basedir)); + if (warn) { + php_error_docref(NULL TSRMLS_CC, E_WARNING, + "open_basedir restriction in effect. File(%s) is not within the allowed path(s): (%s)", path, PG(open_basedir)); + } efree(pathbuf); errno = EPERM; /* we deny permission to open it */ return -1; diff --git a/main/fopen_wrappers.h b/main/fopen_wrappers.h index 42244e84a6..e805d05a66 100644 --- a/main/fopen_wrappers.h +++ b/main/fopen_wrappers.h @@ -27,6 +27,7 @@ PHPAPI int php_fopen_primary_script(zend_file_handle *file_handle TSRMLS_DC); PHPAPI char *expand_filepath(const char *filepath, char *real_path TSRMLS_DC); PHPAPI int php_check_open_basedir(const char *path TSRMLS_DC); +PHPAPI int php_check_open_basedir_ex(const char *path, int warn TSRMLS_DC); PHPAPI int php_check_specific_open_basedir(const char *basedir, const char *path TSRMLS_DC); PHPAPI int php_check_safe_mode_include_dir(char *path TSRMLS_DC);