[php-src] PHP-8.3: Merge branch 'PHP-8.2' into PHP-8.3
| From: | Niels Dossche | Date: | Sat, 30 Mar 2024 17:04:50 +0000 |
| Subject: | [php-src] PHP-8.3: Merge branch 'PHP-8.2' into PHP-8.3 | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-127901@lists.php.net to get a copy of this message | ||
Author: Niels Dossche (nielsdos)
Date: 2024-03-30T18:04:29+01:00
Commit: https://github.com/php/php-src/commit/6a23c7fa91cda9666ec90545fa09f598d9e61114
Raw diff: https://github.com/php/php-src/commit/6a23c7fa91cda9666ec90545fa09f598d9e61114.diff
Merge branch 'PHP-8.2' into PHP-8.3
* PHP-8.2:
Fix GH-13836: Renaming a file in a Phar to an already existing filename causes a NULL pointer
dereference
Changed paths:
A ext/phar/tests/gh13833.phpt
M NEWS
M ext/phar/stream.c
Diff:
diff --git a/NEWS b/NEWS
index 4136823479433..0e57f4ef489dc 100644
--- a/NEWS
+++ b/NEWS
@@ -14,6 +14,10 @@ PHP NEWS
. Fixed bug GH-10495 (feof on OpenSSL stream hangs indefinitely).
(Jakub Zelenka)
+- Phar:
+ . Fixed bug GH-13836 (Renaming a file in a Phar to an already existing
+ filename causes a NULL pointer dereference). (nielsdos)
+
- PHPDBG:
. Fixed bug GH-13827 (Null pointer access of type 'zval' in phpdbg_frame).
(nielsdos)
diff --git a/ext/phar/stream.c b/ext/phar/stream.c
index 3288aa4c2d192..752e15ed7176d 100644
--- a/ext/phar/stream.c
+++ b/ext/phar/stream.c
@@ -858,8 +858,9 @@ static int phar_wrapper_rename(php_stream_wrapper *wrapper, const char *url_from
entry->link = entry->tmp = NULL;
source = entry;
- /* add to the manifest, and then store the pointer to the new guy in entry */
- entry = zend_hash_str_add_mem(&(phar->manifest), ZSTR_VAL(resource_to->path)+1,
ZSTR_LEN(resource_to->path)-1, (void **)&new, sizeof(phar_entry_info));
+ /* add to the manifest, and then store the pointer to the new guy in entry
+ * if it already exists, we overwrite the destination like what copy('phar://...',
'phar://...') does. */
+ entry = zend_hash_str_update_mem(&(phar->manifest), ZSTR_VAL(resource_to->path)+1,
ZSTR_LEN(resource_to->path)-1, (void **)&new, sizeof(phar_entry_info));
entry->filename = estrndup(ZSTR_VAL(resource_to->path)+1,
ZSTR_LEN(resource_to->path)-1);
if (FAILURE == phar_copy_entry_fp(source, entry, &error)) {
diff --git a/ext/phar/tests/gh13833.phpt b/ext/phar/tests/gh13833.phpt
new file mode 100644
index 0000000000000..d1b79d033e0e8
--- /dev/null
+++ b/ext/phar/tests/gh13833.phpt
@@ -0,0 +1,33 @@
+--TEST--
+GH-13836 (Renaming a file in a Phar to an already existing filename causes a NULL pointer
dereference)
+--EXTENSIONS--
+phar
+--INI--
+phar.require_hash=0
+phar.readonly=0
+--FILE--
+<?php
+$fname = __DIR__ . '/gh13836.phar';
+
+$phar = new Phar($fname, 0, 'a.phar');
+$phar['x'] = 'hi1';
+$phar['y'] = 'hi2';
+
+var_dump(rename("phar://a.phar/x", "phar://a.phar/y"));
+
+var_dump(isset($phar['x']));
+var_dump($phar['y']);
+?>
+--CLEAN--
+<?php
+unlink(__DIR__ . '/gh13836.phar');
+?>
+--EXPECTF--
+bool(true)
+bool(false)
+object(PharFileInfo)#2 (2) {
+ ["pathName":"SplFileInfo":private]=>
+ string(%d) "phar://%sgh13836.phar/y"
+ ["fileName":"SplFileInfo":private]=>
+ string(1) "y"
+}