From: Ilia Alshanetsky Date: Tue, 24 Jun 2003 13:56:25 +0000 (+0000) Subject: Fix for bug #24313 (port from dead PHP_5 branch) X-Git-Tag: RELEASE_1_0_2~72 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=6b5b6079da8af0e3b7d3bba2f26854ac8d05885d;p=php Fix for bug #24313 (port from dead PHP_5 branch) --- diff --git a/ext/standard/filestat.c b/ext/standard/filestat.c index 8dabb62004..6f83dc09a3 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 714dc48bff..445e981b8f 100644 --- a/main/fopen_wrappers.c +++ b/main/fopen_wrappers.c @@ -162,9 +162,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)) { @@ -190,8 +195,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 7a3b9592e3..a15897e91e 100644 --- a/main/fopen_wrappers.h +++ b/main/fopen_wrappers.h @@ -28,6 +28,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);