From dbf43f5e0d2fd3f47bf5bc4b05284985117e512a Mon Sep 17 00:00:00 2001 From: Greg Beaver Date: Mon, 14 Apr 2008 15:48:25 +0000 Subject: [PATCH] add test for mkdir() of sub-directory of existing file, and restore the removed free()s with an is_temp_dir test --- ext/phar/dirstream.c | 4 ++++ ext/phar/tests/dir.phpt | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/ext/phar/dirstream.c b/ext/phar/dirstream.c index c4f1ec3c79..90e1818377 100644 --- a/ext/phar/dirstream.c +++ b/ext/phar/dirstream.c @@ -458,6 +458,10 @@ int phar_wrapper_mkdir(php_stream_wrapper *wrapper, char *url_from, int mode, in if ((e = phar_get_entry_info_dir(phar, resource->path + 1, strlen(resource->path + 1), 2, &error TSRMLS_CC))) { /* directory exists, or is a subdirectory of an existing file */ + if (e->is_temp_dir) { + efree(e->filename); + efree(e); + } php_stream_wrapper_log_error(wrapper, options TSRMLS_CC, "phar error: cannot create directory \"%s\" in phar \"%s\", directory already exists", resource->path+1, resource->host); php_url_free(resource); return FAILURE; diff --git a/ext/phar/tests/dir.phpt b/ext/phar/tests/dir.phpt index 578e2df012..1168bd50ea 100644 --- a/ext/phar/tests/dir.phpt +++ b/ext/phar/tests/dir.phpt @@ -34,6 +34,8 @@ ini_set('phar.readonly', 0); // create new phar by mkdir mkdir('phar://' . dirname(__FILE__) . '/ok.phar/fails'); mkdir('phar://' . dirname(__FILE__) . '/ok.phar/fails'); +file_put_contents('phar://' . dirname(__FILE__) . '/ok.phar/sub/directory.txt', 'hi'); +mkdir('phar://' . dirname(__FILE__) . '/ok.phar/sub'); file_put_contents(dirname(__FILE__) . '/oops.phar', ' @@ -57,5 +59,7 @@ Warning: mkdir(): phar error: cannot create directory "phar://%sdir.phar.php/fai Warning: mkdir(): phar error: cannot create directory "fails" in phar "%sok.phar", directory already exists in %sdir.php on line %d +Warning: mkdir(): phar error: cannot create directory "sub" in phar "%sok.phar", directory already exists in %sdir.php on line %d + Warning: mkdir(): internal corruption of phar "%soops.phar" (truncated manifest at stub end) in %sdir.php on line %d ===DONE=== \ No newline at end of file -- 2.50.1