]> granicus.if.org Git - php/commitdiff
Fix for bug #24313 (port from dead PHP_5 branch)
authorIlia Alshanetsky <iliaa@php.net>
Tue, 24 Jun 2003 13:56:25 +0000 (13:56 +0000)
committerIlia Alshanetsky <iliaa@php.net>
Tue, 24 Jun 2003 13:56:25 +0000 (13:56 +0000)
ext/standard/filestat.c
ext/standard/tests/file/bug24313.phpt [new file with mode: 0644]
main/fopen_wrappers.c
main/fopen_wrappers.h

index 8dabb620041d566c2ad53666a70c9bfd37411c04..6f83dc09a333ba5a97019ed7c51742a39b6456f3 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 714dc48bff250cdeff03e9468dc7bb1d8fbb3af9..445e981b8fea2ed17c8f619aee9cbb4be9eaecbc 100644 (file)
@@ -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;
index 7a3b9592e35752a183c80c8073888c04d16b28f3..a15897e91eaf22238afb4a93da91940a418e46fa 100644 (file)
@@ -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);