From cd7750e4baf98705741c45bc93c00084ed11087f Mon Sep 17 00:00:00 2001 From: Antony Dovgal Date: Fri, 1 Jun 2007 13:33:48 +0000 Subject: [PATCH] fix #41518 (file_exists() warns of open_basedir restriction on non-existent file) --- .../tests/general_functions/bug41518.phpt | 28 +++++++++++++++++++ main/fopen_wrappers.c | 12 +++++++- 2 files changed, 39 insertions(+), 1 deletion(-) create mode 100644 ext/standard/tests/general_functions/bug41518.phpt diff --git a/ext/standard/tests/general_functions/bug41518.phpt b/ext/standard/tests/general_functions/bug41518.phpt new file mode 100644 index 0000000000..c15cae1212 --- /dev/null +++ b/ext/standard/tests/general_functions/bug41518.phpt @@ -0,0 +1,28 @@ +--TEST-- +Bug #41518 (file_exists() warns of open_basedir restriction on non-existent file) +--SKIPIF-- + +--INI-- +open_basedir=/tmp/ +--FILE-- + +--EXPECTF-- +bool(true) +bool(false) +Done diff --git a/main/fopen_wrappers.c b/main/fopen_wrappers.c index 476b4c8442..895afc4a6c 100644 --- a/main/fopen_wrappers.c +++ b/main/fopen_wrappers.c @@ -229,8 +229,8 @@ PHPAPI int php_check_specific_open_basedir(const char *basedir, const char *path } } + resolved_name_len = strlen(resolved_name); if (path_tmp[path_len - 1] == PHP_DIR_SEPARATOR) { - resolved_name_len = strlen(resolved_name); if (resolved_name[resolved_name_len - 1] != PHP_DIR_SEPARATOR) { resolved_name[resolved_name_len] = PHP_DIR_SEPARATOR; resolved_name[++resolved_name_len] = '\0'; @@ -246,6 +246,16 @@ PHPAPI int php_check_specific_open_basedir(const char *basedir, const char *path /* File is in the right directory */ return 0; } else { + /* /openbasedir/ and /openbasedir are the same directory */ + if (resolved_basedir_len == (resolved_name_len + 1) && resolved_basedir[resolved_basedir_len - 1] == PHP_DIR_SEPARATOR) { +#if defined(PHP_WIN32) || defined(NETWARE) + if (strncasecmp(resolved_basedir, resolved_name, resolved_name_len) == 0) { +#else + if (strncmp(resolved_basedir, resolved_name, resolved_name_len) == 0) { +#endif + return 0; + } + } return -1; } } else { -- 2.50.1