From: Greg Beaver Date: Mon, 14 Apr 2008 16:26:01 +0000 (+0000) Subject: fix potential segfault if some idiot tries to remove the root directory of a phar... X-Git-Tag: RELEASE_2_0_0b1~417 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=eb252c5c929554485b6b67a5e42bc54f2b202ea9;p=php fix potential segfault if some idiot tries to remove the root directory of a phar, add creation of root directory to test --- diff --git a/ext/phar/dirstream.c b/ext/phar/dirstream.c index bdcd3406a9..1bac2d1c98 100644 --- a/ext/phar/dirstream.c +++ b/ext/phar/dirstream.c @@ -582,7 +582,7 @@ int phar_wrapper_rmdir(php_stream_wrapper *wrapper, char *url, int options, php_ return FAILURE; } - if (!(entry = phar_get_entry_info_dir(phar, resource->path + 1, strlen(resource->path + 1), 2, &error TSRMLS_CC))) { + if (!(entry = phar_get_entry_info_dir(phar, resource->path + 1, strlen(resource->path) - 1, 2, &error TSRMLS_CC))) { if (error) { php_stream_wrapper_log_error(wrapper, options TSRMLS_CC, "phar error: cannot remove directory \"%s\" in phar \"%s\", %s", resource->path+1, resource->host, error); efree(error); diff --git a/ext/phar/tests/dir.phpt b/ext/phar/tests/dir.phpt index d74fcd50a3..0d77aa5ee5 100644 --- a/ext/phar/tests/dir.phpt +++ b/ext/phar/tests/dir.phpt @@ -46,6 +46,9 @@ rmdir('phar://' . dirname(__FILE__) . '/unknown.phar/hi'); ini_set('phar.readonly', 1); rmdir($pname . '/another/dir'); ini_set('phar.readonly', 0); +rmdir($pname); +rmdir($pname . '/'); +mkdir($pname . '/'); ?> ===DONE=== --CLEAN-- @@ -80,4 +83,10 @@ Warning: rmdir(): phar error: cannot remove directory "phar://", no phar archive Warning: rmdir(): phar error: cannot remove directory "hi" in phar "%sunknown.phar", directory does not exist in %sdir.php on line %d Warning: rmdir(): phar error: cannot rmdir directory "phar://%sdir.phar.php/another/dir", write operations disabled in %sdir.php on line %d + +Warning: rmdir(): phar error: cannot remove directory "" in phar "%sdir.phar.php", directory does not exist in %sdir.php on line %d + +Warning: rmdir(): phar error: cannot remove directory "" in phar "%sdir.phar.php", directory does not exist in %sdir.php on line %d + +Warning: mkdir(): phar error: cannot create directory "" in phar "%sdir.phar.php", phar error: invalid path "" must not be empty in %sdir.php on line %d ===DONE=== \ No newline at end of file diff --git a/ext/phar/util.c b/ext/phar/util.c index f07000df87..210088619b 100644 --- a/ext/phar/util.c +++ b/ext/phar/util.c @@ -982,7 +982,7 @@ phar_entry_info *phar_get_entry_info_dir(phar_archive_data *phar, char *path, in { const char *pcr_error; phar_entry_info *entry; - char is_dir = (path[path_len - 1] == '/'); + char is_dir = path_len && (path[path_len - 1] == '/'); if (error) { *error = NULL;