Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions ext/phar/stream.c
Original file line number Diff line number Diff line change
Expand Up @@ -846,6 +846,11 @@ static int phar_wrapper_rename(php_stream_wrapper *wrapper, const char *url_from
php_error_docref(NULL, E_WARNING, "phar error: cannot rename \"%s\" to \"%s\" from extracted phar archive, source has been deleted", url_from, url_to);
return 0;
}
if (zend_string_equals(resource_from->path, resource_to->path)) {
php_url_free(resource_from);
php_url_free(resource_to);
return 1;
}
/* transfer all data over to the new entry */
memcpy((void *) &new, (void *) entry, sizeof(phar_entry_info));
/* mark the old one for deletion */
Expand Down
24 changes: 24 additions & 0 deletions ext/phar/tests/gh25091.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
--TEST--
GH-25091: Use-after-free in rename() when source and destination are the same entry
--EXTENSIONS--
phar
--INI--
phar.readonly=0
--FILE--
<?php
$fname = __DIR__ . '/gh25091.phar';

$phar = new Phar($fname);
$phar['a'] = 'contents';
unset($phar);

var_dump(rename('phar://' . $fname . '/a', 'phar://' . $fname . '/a'));
var_dump(file_get_contents('phar://' . $fname . '/a'));
?>
--CLEAN--
<?php
@unlink(__DIR__ . '/gh25091.phar');
?>
--EXPECT--
bool(true)
string(8) "contents"
Loading