pajoye Tue, 26 Jul 2011 17:44:20 +0000 Revision: http://svn.php.net/viewvc?view=revision&revision=313743
Log: - Fixed bug 55124, recursive mkdir fails with current (dot) directory in path Bug: https://bugs.php.net/55124 (Verified) recursive mkdir fails with current (dot) directory in path Changed paths: A php/php-src/branches/PHP_5_4/ext/standard/tests/file/bug55124.phpt U php/php-src/branches/PHP_5_4/main/streams/plain_wrapper.c A php/php-src/trunk/ext/standard/tests/file/bug55124.phpt U php/php-src/trunk/main/streams/plain_wrapper.c Added: php/php-src/branches/PHP_5_4/ext/standard/tests/file/bug55124.phpt =================================================================== --- php/php-src/branches/PHP_5_4/ext/standard/tests/file/bug55124.phpt (rev 0) +++ php/php-src/branches/PHP_5_4/ext/standard/tests/file/bug55124.phpt 2011-07-26 17:44:20 UTC (rev 313743) @@ -0,0 +1,18 @@ +--TEST-- +Bug #55124 (recursive mkdir fails with current (dot) directory in path) +--FILE-- +<?php +$old_dir_path = getcwd(); +chdir(__DIR__); +mkdir('a/./b', 0755, true); +if (is_dir('a/b')) { + rmdir('a/b'); +} +if (is_dir('/a')) { + rmdir('a'); +} +chdir($old_dir_path); +echo "OK"; +?> +--EXPECT-- +OK Modified: php/php-src/branches/PHP_5_4/main/streams/plain_wrapper.c =================================================================== --- php/php-src/branches/PHP_5_4/main/streams/plain_wrapper.c 2011-07-26 16:48:46 UTC (rev 313742) +++ php/php-src/branches/PHP_5_4/main/streams/plain_wrapper.c 2011-07-26 17:44:20 UTC (rev 313743) @@ -1147,25 +1147,19 @@ 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 @@ } } } - efree(buf); } if (ret < 0) { /* Failure */ Added: php/php-src/trunk/ext/standard/tests/file/bug55124.phpt =================================================================== --- php/php-src/trunk/ext/standard/tests/file/bug55124.phpt (rev 0) +++ php/php-src/trunk/ext/standard/tests/file/bug55124.phpt 2011-07-26 17:44:20 UTC (rev 313743) @@ -0,0 +1,18 @@ +--TEST-- +Bug #55124 (recursive mkdir fails with current (dot) directory in path) +--FILE-- +<?php +$old_dir_path = getcwd(); +chdir(__DIR__); +mkdir('a/./b', 0755, true); +if (is_dir('a/b')) { + rmdir('a/b'); +} +if (is_dir('/a')) { + rmdir('a'); +} +chdir($old_dir_path); +echo "OK"; +?> +--EXPECT-- +OK Modified: php/php-src/trunk/main/streams/plain_wrapper.c =================================================================== --- php/php-src/trunk/main/streams/plain_wrapper.c 2011-07-26 16:48:46 UTC (rev 313742) +++ php/php-src/trunk/main/streams/plain_wrapper.c 2011-07-26 17:44:20 UTC (rev 313743) @@ -1147,25 +1147,19 @@ 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 @@ } } } - efree(buf); } if (ret < 0) { /* Failure */
-- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php