From: Greg Beaver Date: Tue, 3 Feb 2009 18:29:46 +0000 (+0000) Subject: MFB: fix bug #47085:rename() returns true even if the file in PHAR does not exist X-Git-Tag: php-5.4.0alpha1~191^2~4336 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=f232c7f945812bb21cfb0f4fc35557acacf6c7a2;p=php MFB: fix bug #47085:rename() returns true even if the file in PHAR does not exist --- diff --git a/ext/phar/stream.c b/ext/phar/stream.c index fa0049fbb0..bc38f5e75a 100644 --- a/ext/phar/stream.c +++ b/ext/phar/stream.c @@ -888,6 +888,14 @@ static int phar_wrapper_rename(php_stream_wrapper *wrapper, char *url_from, char is_dir = entry->is_dir; } else { is_dir = zend_hash_exists(&(phar->virtual_dirs), resource_from->path+1, strlen(resource_from->path)-1); + if (!is_dir) { + /* file does not exist */ + php_url_free(resource_from); + php_url_free(resource_to); + php_error_docref(NULL TSRMLS_CC, E_WARNING, "phar error: cannot rename \"%s\" to \"%s\" from extracted phar archive, source does not exist", url_from, url_to); + return 0; + + } } /* Rename directory. Update all nested paths */ diff --git a/ext/phar/tests/bug47085.phpt b/ext/phar/tests/bug47085.phpt new file mode 100644 index 0000000000..9aaaed0670 --- /dev/null +++ b/ext/phar/tests/bug47085.phpt @@ -0,0 +1,24 @@ +--TEST-- +Phar: PHP bug #47085: "rename() returns true even if the file in PHAR does not exist" +--SKIPIF-- + +--INI-- +phar.require_hash=0 +phar.readonly=0 +--FILE-- + +===DONE=== +--CLEAN-- + +--EXPECTF-- +Warning: rename(): phar error: cannot rename "phar://a.phar/x" to "phar://a.phar/y" from extracted phar archive, source does not exist in %sbug47085.php on line %d +bool(false) +===DONE=== \ No newline at end of file