]> granicus.if.org Git - php/commitdiff
MFH: fix #41518 (file_exists() warns of open_basedir restriction on non-existent...
authorAntony Dovgal <tony2001@php.net>
Fri, 1 Jun 2007 13:35:23 +0000 (13:35 +0000)
committerAntony Dovgal <tony2001@php.net>
Fri, 1 Jun 2007 13:35:23 +0000 (13:35 +0000)
NEWS
ext/standard/tests/general_functions/bug41518.phpt [new file with mode: 0644]
main/fopen_wrappers.c

diff --git a/NEWS b/NEWS
index 4a4313b6edfddb568184ec5011564445a0c2b250..e2ac69de2038341557b9fc4c7bc383a4413d7797 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -1,6 +1,8 @@
 PHP                                                                        NEWS
 |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
 ?? ??? 2007, PHP 5.2.4
+- Fixed bug #41518 (file_exists() warns of open_basedir restriction on 
+  non-existent file). (Tony)
 - Fixed bug #39330 (apache2handler does not call shutdown actions before 
   apache child die). (isk at ecommerce dot com, Gopal, Tony)
 
diff --git a/ext/standard/tests/general_functions/bug41518.phpt b/ext/standard/tests/general_functions/bug41518.phpt
new file mode 100644 (file)
index 0000000..c15cae1
--- /dev/null
@@ -0,0 +1,28 @@
+--TEST--
+Bug #41518 (file_exists() warns of open_basedir restriction on non-existent file)
+--SKIPIF--
+<?php
+/* let's use /tmp here */
+$tmp_dir = "/tmp";
+if (!is_dir($tmp_dir) || realpath($tmp_dir) !== $tmp_dir) {
+       die("skip");
+}
+?>
+--INI--
+open_basedir=/tmp/
+--FILE--
+<?php
+
+$tmp_dir = "/tmp";
+$tmp_file = $tmp_dir."/bug41418.tmp";
+
+touch($tmp_file);
+var_dump(file_exists($tmp_file)); //exists
+var_dump(file_exists($tmp_file."nosuchfile")); //doesn't exist
+
+echo "Done\n";
+?>
+--EXPECTF--    
+bool(true)
+bool(false)
+Done
index 88003527b54641917d689f1be3e18aec4057649b..c27a60f1285d61e7be2636ea0ac23edc2bea34cd 100644 (file)
@@ -172,8 +172,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';
@@ -189,6 +189,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 {