Skip to content

Commit e204df5

Browse files
committed
Fix #77919: Potential UAF in Phar RSHUTDOWN
We have to properly clean up in case phar_flush() is failing. We also make the expectation of the respective test case less liberal to avoid missing such bugs in the future. (cherry picked from commit cd1101e)
1 parent e648fa4 commit e204df5

File tree

3 files changed

+10
-2
lines changed

3 files changed

+10
-2
lines changed

NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ PHP NEWS
1111
- OPcache:
1212
. Fixed bug #78341 (Failure to detect smart branch in DFA pass). (Nikita)
1313

14+
- Phar:
15+
. Fixed bug #77919 (Potential UAF in Phar RSHUTDOWN). (cmb)
16+
1417
- Phpdbg:
1518
. Fixed bug #78297 (Include unexistent file memory leak). (Nikita)
1619

ext/phar/phar_object.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1990,7 +1990,7 @@ static zend_object *phar_rename_archive(phar_archive_data **sphar, char *ext) /*
19901990
char *newname = NULL, *newpath = NULL;
19911991
zval ret, arg1;
19921992
zend_class_entry *ce;
1993-
char *error;
1993+
char *error = NULL;
19941994
const char *pcr_error;
19951995
size_t ext_len = ext ? strlen(ext) : 0;
19961996
size_t new_len, oldname_len, phar_ext_len;
@@ -2200,6 +2200,8 @@ static zend_object *phar_rename_archive(phar_archive_data **sphar, char *ext) /*
22002200
phar_flush(phar, 0, 0, 1, &error);
22012201

22022202
if (error) {
2203+
zend_hash_str_del(&(PHAR_G(phar_fname_map)), newpath, phar->fname_len);
2204+
*sphar = NULL;
22032205
zend_throw_exception_ex(spl_ce_BadMethodCallException, 0, "%s", error);
22042206
efree(error);
22052207
efree(oldpath);

ext/phar/tests/bug71488.phpt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,7 @@ DONE
1515
?>
1616
--EXPECTF--
1717
Fatal error: Uncaught BadMethodCallException: tar-based phar "%s/bug71488.test" cannot be created, link "%s" is too long for format in %sbug71488.php:%d
18-
Stack trace:%A
18+
Stack trace:
19+
#0 %s(%d): PharData->decompress('test')
20+
#1 {main}
21+
thrown in %s on line %d

0 commit comments

Comments
 (0)