]> granicus.if.org Git - php/commitdiff
- prevent unexpectable behaviors (for the user) with invalid path and update tests...
authorPierre Joye <pajoye@php.net>
Sun, 7 Feb 2010 20:45:46 +0000 (20:45 +0000)
committerPierre Joye <pajoye@php.net>
Sun, 7 Feb 2010 20:45:46 +0000 (20:45 +0000)
22 files changed:
ext/standard/tests/array/array_flip_variation2.phpt
ext/standard/tests/array/uasort_variation5.phpt
ext/standard/tests/file/rename_variation13-win32.phpt
ext/standard/tests/file/tempnam_variation3-win32.phpt
ext/standard/tests/general_functions/bug49847.phpt
ext/standard/tests/general_functions/bug50732.phpt
ext/standard/tests/general_functions/proc_nice_basic.phpt
ext/standard/tests/general_functions/proc_nice_error.phpt
ext/standard/tests/general_functions/proc_nice_variation1.phpt
ext/standard/tests/general_functions/proc_nice_variation2.phpt
ext/standard/tests/general_functions/proc_nice_variation3.phpt
ext/standard/tests/general_functions/proc_nice_variation5.phpt
ext/standard/tests/general_functions/proc_nice_variation6.phpt
ext/standard/tests/general_functions/proc_nice_variation7.phpt
ext/standard/tests/general_functions/strval.phpt
ext/standard/tests/streams/bug49936.phpt
ext/standard/tests/streams/bug49936_win32.phpt [new file with mode: 0644]
ext/standard/tests/streams/stream_resolve_include_path.phpt
main/php_open_temporary_file.c
main/streams/plain_wrapper.c
win32/winutil.c
win32/winutil.h

index 1474a6955b5229638e25153cf4c0e448be4b662d..997c391306e5cf751d4603cad8fb3c679155dab4 100644 (file)
Binary files a/ext/standard/tests/array/array_flip_variation2.phpt and b/ext/standard/tests/array/array_flip_variation2.phpt differ
index 22d9da31c532a4ede6dfc923b334f732e629d10f..e6996a55febfe5d436c4bf8de06282b144b2be4b 100644 (file)
@@ -139,7 +139,7 @@ array(4) {
   [1]=>
   string(7) "Heredoc"
   [3]=>
-  string(43) "heredoc string   with!@# and 123
+  string(4%d) "heredoc string  with!@# and 123
 Test this!!!"
 }
 Done
index 290095629e4a2f28c3c4e0b043260fb63ef33a43..ccbb62185089f93a884886d8c1b9d9ad3cd70fbf 100644 (file)
Binary files a/ext/standard/tests/file/rename_variation13-win32.phpt and b/ext/standard/tests/file/rename_variation13-win32.phpt differ
index ec7718f970cb94e761847b971980ed95658cd139..080bce0fb8cc322a588fd88c7c0a66de9a975de0 100644 (file)
@@ -39,11 +39,20 @@ for( $i=0; $i<count($names_arr); $i++ ) {
   echo "-- Iteration $i --\n";
   $file_name = tempnam("$file_path", $names_arr[$i]);
 
-  /* creating the files in existing dir */
-  if( file_exists($file_name) ) {
-    echo "File name is => ";
-    print($file_name);
-    echo "\n";
+       /* creating the files in existing dir */
+       if (file_exists($file_name) && !$res_arr[$i]) {
+               echo "Failed\n";
+       }
+       if ($res_arr[$i]) {
+               $file_dir = dirname($file_name);
+               if (realpath($file_dir) == $file_path || realpath($file_dir . "\\") == $file_path) {
+                       echo "OK\n";
+               } else {
+                       echo "Failed, not created in the correct directory " . realpath($file_dir) . ' vs ' . $file_path ."\n";
+               }
+               
+               if (!is_writable($file_name)) {
+                       printf("%o\n", fileperms($file_name) );
 
     echo "File permissions are => ";
     printf("%o", fileperms($file_name) );
@@ -94,9 +103,8 @@ File name is => %s\%s
 File permissions are => 100666
 File created in => directory specified
 -- Iteration 5 --
-File name is => %s\%s
-File permissions are => 100666
-File created in => directory specified
+Failed, not created in the correct directory %s vs %s
+0
 -- Iteration 6 --
 File name is => %s\%s
 File permissions are => 100666
index 637abd24ea1fdec2b24849775d85790bcba7fea3..8895202d0cbf3e2c384500bd9b87af3970cc6c6a 100644 (file)
@@ -2,35 +2,24 @@
 Bug #49847 (exec() fails on lines larger then 4095 bytes)
 --FILE--
 <?php
-exec("printf %4098d 1", $output);
-var_dump($output);
-?>
---EXPECT--
-array(1) {
-  [0]=>
-  string(4098) "                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 1"
+$iswin =  substr(PHP_OS, 0, 3) == "WIN";
+
+if ($iswin) {
+       $f = dirname(__FILE__) . '\\bug49847.tmp';
+       $s = str_repeat(' ', 4097);
+       $s .= '1';
+       file_put_contents($f, $s);
+       exec('more ' . $f, $output);
+} else {
+       exec("printf %4098d 1", $output);
 }
---TEST--
-Bug #49847 (exec() fails on lines larger then 4095 bytes)
---FILE--
-<?php
-exec("printf %4098d 1", $output);
 var_dump($output);
-?>
---EXPECT--
-array(1) {
-  [0]=>
-  string(4098) "                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 1"
+if ($iswin) {
+       unlink($f);
 }
---TEST--
-Bug #49847 (exec() fails on lines larger then 4095 bytes)
---FILE--
-<?php
-exec("printf %4098d 1", $output);
-var_dump($output);
 ?>
---EXPECT--
+--EXPECTF--
 array(1) {
   [0]=>
-  string(4098) "                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 1"
+  string(4098) "%s 1"
 }
index e036b47ed66d088e9c68ed3a90a02df8d403a078..ed8341decb8479d3f1e76d5d93cace8a9c3d3a57 100644 (file)
@@ -10,27 +10,3 @@ array(1) {
   [0]=>
   string(1) "x"
 }
---TEST--
-Bug #50732 (exec() adds single byte twice to $output array)
---FILE--
-<?php
-exec("echo x", $output);
-var_dump($output);
-?>
---EXPECT--
-array(1) {
-  [0]=>
-  string(1) "x"
-}
---TEST--
-Bug #50732 (exec() adds single byte twice to $output array)
---FILE--
-<?php
-exec("echo x", $output);
-var_dump($output);
-?>
---EXPECT--
-array(1) {
-  [0]=>
-  string(1) "x"
-}
index 5a95756276c0461a75225899e5cc0207eaedd9a5..3a958901a240e8238c73fc7763af3d291c58e121 100644 (file)
@@ -5,6 +5,10 @@ Italian PHP TestFest 2009 Cesena 19-20-21 june
 Fabio Fabbrucci (fabbrucci@grupporetina.com)
 Michele Orselli (mo@ideato.it)
 Simone Gentili (sensorario@gmail.com)
+--SKIPIF--
+<?php
+if(!function_exists('proc_nice')) die("skip. proc_nice not available ");
+?>
 --FILE--
 <?php
        function getNice($id)
index c50812c863c5c4bd63136ad9a597d23499245f22..09f84fa552a13d2a7c0d94b30f6ca3ed10853307 100644 (file)
@@ -1,5 +1,9 @@
 --TEST--
 Test function proc_nice() by calling it more than or less than its expected arguments
+--SKIPIF--
+<?php
+if(!function_exists('proc_nice')) die("skip. proc_nice not available ");
+?>
 --FILE--
 <?php
 
index b86155c4b2504695e52d5f60e3a17798705d3229..8c2bdf0df6b162a73c45a07452a1eee84a80806e 100644 (file)
@@ -5,6 +5,10 @@ Italian PHP TestFest 2009 Cesena 19-20-21 june
 Fabio Fabbrucci (fabbrucci@grupporetina.com)
 Michele Orselli (mo@ideato.it)
 Simone Gentili (sensorario@gmail.com)
+--SKIPIF--
+<?php
+if(!function_exists('proc_nice')) die("skip. proc_nice not available ");
+?>
 --FILE--
 <?php
 
index 620fe91447ed33ca74ee6a5ce00e3bbd75ba5388..42cbf9e00fd5ecd575d6c95660781e8ab3b8fee7 100644 (file)
@@ -5,6 +5,10 @@ Italian PHP TestFest 2009 Cesena 19-20-21 june
 Fabio Fabbrucci (fabbrucci@grupporetina.com)
 Michele Orselli (mo@ideato.it)
 Simone Gentili (sensorario@gmail.com)
+--SKIPIF--
+<?php
+if(!function_exists('proc_nice')) die("skip. proc_nice not available ");
+?>
 --FILE--
 <?php
 
index 458126db4a218ff00fa3e2c98351b5d96099269b..46b444358e0b3f1a20f3b25772ee1e6c3452d919 100644 (file)
@@ -5,6 +5,10 @@ Italian PHP TestFest 2009 Cesena 19-20-21 june
 Fabio Fabbrucci (fabbrucci@grupporetina.com)
 Michele Orselli (mo@ideato.it)
 Simone Gentili (sensorario@gmail.com)
+--SKIPIF--
+<?php
+if(!function_exists('proc_nice')) die("skip. proc_nice not available ");
+?>
 --FILE--
 <?php
 
index efce8cf791a06d01c46079c083a768799cac1c1b..c22ca56ca45156f8bc00a0d0dd15b9bed3d80325 100644 (file)
@@ -7,7 +7,8 @@ Michele Orselli (mo@ideato.it)
 Simone Gentili (sensorario@gmail.com)
 --SKIPIF--
 <?php
-        if(posix_geteuid() == 0) print "skip - Cannot run test as root.";
+       if(!function_exists('proc_nice')) die("skip. proc_nice not available ");
+       if(posix_geteuid() == 0) print "skip - Cannot run test as root.";
 ?>
 --FILE--
 <?php
index b4babd59301a48bbcf30d4f11e5e38c939e4aecc..d52c0c0796518852306a0bc494b8604e88103398 100644 (file)
@@ -5,6 +5,10 @@ Italian PHP TestFest 2009 Cesena 19-20-21 june
 Fabio Fabbrucci (fabbrucci@grupporetina.com)
 Michele Orselli (mo@ideato.it)
 Simone Gentili (sensorario@gmail.com)
+--SKIPIF--
+<?php
+if(!function_exists('proc_nice')) die("skip. proc_nice not available ");
+?>
 --FILE--
 <?php
 
index 70487dd09da0f5a20f0ab24eb4433d4a89864c66..26dbab503158cdd23f0cba620ebec2b68f3fe99d 100644 (file)
@@ -5,6 +5,10 @@ Italian PHP TestFest 2009 Cesena 19-20-21 june
 Fabio Fabbrucci (fabbrucci@grupporetina.com)
 Michele Orselli (mo@ideato.it)
 Simone Gentili (sensorario@gmail.com)
+--SKIPIF--
+<?php
+if(!function_exists('proc_nice')) die("skip. proc_nice not available ");
+?>
 --FILE--
 <?php
 
index 1789e41d668821d41ed44fa77f5ec0198670a6cd..3506785781378e33b741b5df4af5bbb717bfb891 100644 (file)
@@ -267,10 +267,10 @@ string(4) "true"
 -- Iteration 54 --
 string(4) "true"
 -- Iteration 55 --
-string(54) "This is a multiline heredoc
+string(5%d) "This is a multiline heredoc
 string. Numeric = 1232455."
 -- Iteration 56 --
-string(10) "12345
+string(1%d) "12345
 2345"
 -- Iteration 57 --
 string(0) ""
index 7b089a7889fe26c5906a366ab230fdc27eedd628..d77e161c5f68229c2d247135e9912df3db345890 100644 (file)
@@ -1,5 +1,10 @@
 --TEST--
 Bug #49936 (crash with ftp stream in php_stream_context_get_option())
+--SKIPIF--
+<?php
+if( substr(PHP_OS, 0, 3) == "WIN" )
+  die("skip. Do not run on Windows");
+?>
 --FILE--
 <?php
 
diff --git a/ext/standard/tests/streams/bug49936_win32.phpt b/ext/standard/tests/streams/bug49936_win32.phpt
new file mode 100644 (file)
index 0000000..4db4a50
--- /dev/null
@@ -0,0 +1,30 @@
+--TEST--\r
+Bug #49936 (crash with ftp stream in php_stream_context_get_option())\r
+--SKIPIF--\r
+<?php\r
+if( substr(PHP_OS, 0, 3) != "WIN" )\r
+  die("skip. Do run on Windows only");\r
+?>\r
+--INI--\r
+default_socket_timeout=2\r
+--FILE--\r
+<?php\r
+\r
+$dir = 'ftp://your:self@localhost/';\r
+\r
+var_dump(opendir($dir));\r
+var_dump(opendir($dir));\r
+\r
+?>\r
+--EXPECTF--\r
+Warning: opendir(): connect() failed: %s\r
+ in %s on line %d\r
+\r
+Warning: opendir(ftp://...@localhost/): failed to open dir: operation failed in %s on line %d\r
+bool(false)\r
+\r
+Warning: opendir(): connect() failed: %s\r
+ in %s on line %d\r
+\r
+Warning: opendir(ftp://...@localhost/): failed to open dir: operation failed in %s on line %d\r
+bool(false)\r
index 01c05a5ca2d4a5624a046fde72a78b201e90698c..aea5cdd96ca89f0d055bdef47d6f155261eeeedb 100644 (file)
@@ -32,6 +32,6 @@ rmdir($include_path);
 Warning: stream_resolve_include_path() expects exactly 1 parameter, 0 given in %s on line %d
 NULL
 bool(false)
-string(%d) "%s/test_path/file"
-string(%d) "%s/test_path/nested/file"
+string(%d) "%stest_path%sfile"
+string(%d) "%stest_path%snested%sfile"
 
index 942eeacea4df2bda745903fe9b34181c2fa72875..cf17f27d66c6fa419df50f0846ab9fbe33f05b0b 100644 (file)
@@ -113,6 +113,13 @@ static int php_do_open_temporary_file(const char *path, const char *pfx, char **
                return -1;
        }
 
+#ifdef PHP_WIN32
+       if (!php_win32_check_trailing_space(pfx, (const int)strlen(pfx))) {
+               SetLastError(ERROR_INVALID_NAME);
+               return -1;
+       }
+#endif
+
        if (!VCWD_GETCWD(cwd, MAXPATHLEN)) {
                cwd[0] = '\0';
        }
@@ -138,12 +145,14 @@ static int php_do_open_temporary_file(const char *path, const char *pfx, char **
        }
 
 #ifdef PHP_WIN32
+
        if (GetTempFileName(new_state.cwd, pfx, 0, opened_path)) {
                /* Some versions of windows set the temp file to be read-only,
                 * which means that opening it will fail... */
                VCWD_CHMOD(opened_path, 0600);
                fd = VCWD_OPEN_MODE(opened_path, open_flags, 0600);
        }
+
 #elif defined(HAVE_MKSTEMP)
        fd = mkstemp(opened_path);
 #else
@@ -151,6 +160,7 @@ static int php_do_open_temporary_file(const char *path, const char *pfx, char **
                fd = VCWD_OPEN(opened_path, open_flags);
        }
 #endif
+
        if (fd == -1 || !opened_path_p) {
                efree(opened_path);
        } else {
index 8d94c27c227355cf59ac2147687207c45aca5617..f3722d9fc53e4a585c9801a45afa123209d302fe 100644 (file)
@@ -39,6 +39,9 @@
 #include "SAPI.h"
 
 #include "php_streams_int.h"
+#ifdef PHP_WIN32
+# include "win32/winutil.h"
+#endif
 
 #define php_stream_fopen_from_fd_int(fd, mode, persistent_id)  _php_stream_fopen_from_fd_int((fd), (mode), (persistent_id) STREAMS_CC TSRMLS_CC)
 #define php_stream_fopen_from_fd_int_rel(fd, mode, persistent_id)       _php_stream_fopen_from_fd_int((fd), (mode), (persistent_id) STREAMS_REL_CC TSRMLS_CC)
@@ -1060,6 +1063,17 @@ static int php_plain_files_rename(php_stream_wrapper *wrapper, char *url_from, c
                return 0;
        }
 
+#ifdef PHP_WIN32
+       if (!php_win32_check_trailing_space(url_from, strlen(url_from))) {
+               php_win32_docref2_from_error(ERROR_INVALID_NAME, url_from, url_to TSRMLS_CC);
+               return 0;
+       }
+       if (!php_win32_check_trailing_space(url_to, strlen(url_to))) {
+               php_win32_docref2_from_error(ERROR_INVALID_NAME, url_from, url_to TSRMLS_CC);
+               return 0;
+       }
+#endif
+
        if ((p = strstr(url_from, "://")) != NULL) {
                url_from = p + 3;
        }
@@ -1225,6 +1239,9 @@ static int php_plain_files_mkdir(php_stream_wrapper *wrapper, char *dir, int mod
 
 static int php_plain_files_rmdir(php_stream_wrapper *wrapper, char *url, int options, php_stream_context *context TSRMLS_DC)
 {
+#if PHP_WIN32
+       int url_len = strlen(url);
+#endif
        if (PG(safe_mode) &&(!php_checkuid(url, NULL, CHECKUID_CHECK_FILE_AND_DIR))) {
                return 0;
        }
@@ -1233,6 +1250,13 @@ static int php_plain_files_rmdir(php_stream_wrapper *wrapper, char *url, int opt
                return 0;
        }
 
+#if PHP_WIN32
+       if (!php_win32_check_trailing_space(url, url_len)) {
+               php_error_docref1(NULL TSRMLS_CC, url, E_WARNING, "%s", strerror(ENOENT));
+               return 0;
+       }
+#endif
+
        if (VCWD_RMDIR(url) < 0) {
                php_error_docref1(NULL TSRMLS_CC, url, E_WARNING, "%s", strerror(errno));
                return 0;
index 7e1cf3fc91520cf18af1927a4ac284e03a946925..24b00edfae438c4cccb92126483e2914a0a71367 100644 (file)
@@ -31,3 +31,18 @@ PHPAPI char *php_win_err(int error)
 
        return (buf ? (char *) buf : "");
 }
+
+int php_win32_check_trailing_space(const char * path, const int path_len) {
+       if (path_len < 1) {
+               return 1;
+       }
+       if (path) {
+               if (path[0] == ' ' || path[path_len - 1] == ' ') {
+                       return 0;
+               } else {
+                       return 1;
+               }
+       } else {
+               return 0;
+       }
+}
index 36b10200cbae557e6f0e3b3df0fdb86d54a97aec..8ee75752da792b4a790b121a10b93e8a76a4c9a2 100644 (file)
@@ -19,3 +19,4 @@
 PHPAPI char *php_win_err(int error);
 
 #define php_win_err()  php_win_err(GetLastError())
+int php_win32_check_trailing_space(const char * path, const int path_len);