]> granicus.if.org Git - php/commitdiff
MFH: Fixed bug #24313 (file_exist() warning on non-existent files when
authorIlia Alshanetsky <iliaa@php.net>
Tue, 24 Jun 2003 13:44:57 +0000 (13:44 +0000)
committerIlia Alshanetsky <iliaa@php.net>
Tue, 24 Jun 2003 13:44:57 +0000 (13:44 +0000)
open_basedir is used).

NEWS
ext/standard/filestat.c
ext/standard/tests/file/bug24313.phpt [new file with mode: 0644]
main/fopen_wrappers.c
main/fopen_wrappers.h

diff --git a/NEWS b/NEWS
index f0c16a3c20262eb7d70a8fa72e5315b85069cb4b..7e60eeaaf4f26de5fb5eea18211bd806e11993e4 100644 (file)
--- 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
index a5d1899dcffd96f4c080678e191b652dc5f864f3..94580f6fdd35ad9cd82875fbc713742759b2d832 100644 (file)
@@ -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 (file)
index 0000000..67b7cf8
--- /dev/null
@@ -0,0 +1,10 @@
+--TEST--
+Bug #24313: file_exists() warning on non-existant files when is open_basedir enabled
+--INI--
+open_basedir=/tmp
+--FILE--
+<?php
+       var_dump(file_exists("./foobar"));
+?>
+--EXPECT--
+bool(false)
index 6f673f7bc0f0afb6c7ce5d133667387a4f5d2cb8..f9ab69a6acfb6a06a4e03f4eed95610d8edf9402 100644 (file)
@@ -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;
index 42244e84a64d980fff44d20fb104143d6fe255e4..e805d05a663f6953f1b9c3c168461d7ba4945dfb 100644 (file)
@@ -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);