summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGreg Beaver <cellog@php.net>2009-02-03 18:29:25 +0000
committerGreg Beaver <cellog@php.net>2009-02-03 18:29:25 +0000
commitfd5be66d13b86fd6638279a4695ab874bbe14c39 (patch)
tree9218cd21db8bc3d9e3b5d422c02eaf8bdcb13621
parentb634bf4ce8939a854dd0afb371454a15c9722c39 (diff)
downloadphp-git-fd5be66d13b86fd6638279a4695ab874bbe14c39.tar.gz
fix bug #47085:rename() returns true even if the file in PHAR does not exist
-rw-r--r--NEWS1
-rw-r--r--ext/phar/stream.c8
-rw-r--r--ext/phar/tests/bug47085.phpt24
3 files changed, 33 insertions, 0 deletions
diff --git a/NEWS b/NEWS
index d71cb9758d..f11320e65a 100644
--- a/NEWS
+++ b/NEWS
@@ -3,6 +3,7 @@ PHP NEWS
?? ??? 2009, PHP 5.3.0 Beta 2
- Fixed bug #47265 (generating phar.phar failes because of safe_mode). (Greg)
- Fixed bug #47229 (preg_quote() should escape the '-' char). (Nuno)
+- Fixed bug #47085 (rename() returns true even if the file in PHAR does not exist). (Greg)
- Fixed bug #47031 (Fix constants in DualIterator example). (Etienne)
- Fixed bug #46347 (parse_ini_file() doesn't support * in keys). (Nuno)
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--
+<?php if (!extension_loaded("phar")) die("skip"); ?>
+--INI--
+phar.require_hash=0
+phar.readonly=0
+--FILE--
+<?php
+$fname = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar';
+
+$phar = new Phar($fname, 0, 'a.phar');
+$phar['x'] = 'hi';
+unset($phar);
+rename("phar://a.phar/x", "phar://a.phar/y");
+var_dump(rename("phar://a.phar/x", "phar://a.phar/y"));
+?>
+===DONE===
+--CLEAN--
+<?php unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar');?>
+--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