]> granicus.if.org Git - php/commitdiff
- Fixed bug 55124, recursive mkdir fails with current (dot) directory in path
authorPierre Joye <pajoye@php.net>
Tue, 26 Jul 2011 17:44:20 +0000 (17:44 +0000)
committerPierre Joye <pajoye@php.net>
Tue, 26 Jul 2011 17:44:20 +0000 (17:44 +0000)
ext/standard/tests/file/bug55124.phpt [new file with mode: 0644]
main/streams/plain_wrapper.c

diff --git a/ext/standard/tests/file/bug55124.phpt b/ext/standard/tests/file/bug55124.phpt
new file mode 100644 (file)
index 0000000..892d450
--- /dev/null
@@ -0,0 +1,18 @@
+--TEST--\r
+Bug #55124 (recursive mkdir fails with current (dot) directory in path)\r
+--FILE--\r
+<?php\r
+$old_dir_path = getcwd();\r
+chdir(__DIR__);\r
+mkdir('a/./b', 0755, true);\r
+if (is_dir('a/b')) {\r
+       rmdir('a/b');\r
+}\r
+if (is_dir('/a')) {\r
+       rmdir('a');\r
+}\r
+chdir($old_dir_path);\r
+echo "OK";\r
+?>\r
+--EXPECT--\r
+OK\r
index 041a0e34e2e650fe3c1c047d2e0a64c69ba3a46f..8303adb5b12083f89da81934ccd089586a40819e 100644 (file)
@@ -1147,24 +1147,18 @@ static int php_plain_files_mkdir(php_stream_wrapper *wrapper, char *dir, int mod
                ret = php_mkdir(dir, mode TSRMLS_CC);
        } else {
                /* we look for directory separator from the end of string, thus hopefuly reducing our work load */
-               char *e, *buf;
+               char *e;
                struct stat sb;
                int dir_len = strlen(dir);
                int offset = 0;
+               char buf[MAXPATHLEN];
 
-               buf = estrndup(dir, dir_len);
-
-#ifdef PHP_WIN32
-               e = buf;
-               while (*e) {
-                       if (*e == '/') {
-                               *e = DEFAULT_SLASH;
-                       }
-                       e++;
+               if (!expand_filepath_with_mode(dir, buf, NULL, 0, CWD_EXPAND  TSRMLS_CC)) {
+                       php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid path");
+                       return 0;
                }
-#else
-               e = buf + dir_len;
-#endif
+
+               e = buf +  strlen(buf);
 
                if ((p = memchr(buf, DEFAULT_SLASH, dir_len))) {
                        offset = p - buf + 1;
@@ -1216,7 +1210,6 @@ static int php_plain_files_mkdir(php_stream_wrapper *wrapper, char *dir, int mod
                                }
                        }
                }
-               efree(buf);
        }
        if (ret < 0) {
                /* Failure */