diff options
author | Christoph M. Becker <cmbecker69@gmx.de> | 2019-07-29 16:08:03 +0200 |
---|---|---|
committer | Christoph M. Becker <cmbecker69@gmx.de> | 2019-07-30 09:14:05 +0200 |
commit | e204df55ac10a3f7d4387992ea546e46860fb955 (patch) | |
tree | cce91c9e6d1dbf134151efdc54018617871a45ec | |
parent | e648fa4699e8d072db6db34fcc09826e8127fab8 (diff) | |
download | php-git-e204df55ac10a3f7d4387992ea546e46860fb955.tar.gz |
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 cd1101e8c87aa175c2d5e87ddec656e50ef4ab5d)
-rw-r--r-- | NEWS | 3 | ||||
-rw-r--r-- | ext/phar/phar_object.c | 4 | ||||
-rw-r--r-- | ext/phar/tests/bug71488.phpt | 5 |
3 files changed, 10 insertions, 2 deletions
@@ -11,6 +11,9 @@ PHP NEWS - OPcache: . Fixed bug #78341 (Failure to detect smart branch in DFA pass). (Nikita) +- Phar: + . Fixed bug #77919 (Potential UAF in Phar RSHUTDOWN). (cmb) + - Phpdbg: . Fixed bug #78297 (Include unexistent file memory leak). (Nikita) diff --git a/ext/phar/phar_object.c b/ext/phar/phar_object.c index f2e65b32f0..ed5c546adc 100644 --- a/ext/phar/phar_object.c +++ b/ext/phar/phar_object.c @@ -1990,7 +1990,7 @@ static zend_object *phar_rename_archive(phar_archive_data **sphar, char *ext) /* char *newname = NULL, *newpath = NULL; zval ret, arg1; zend_class_entry *ce; - char *error; + char *error = NULL; const char *pcr_error; size_t ext_len = ext ? strlen(ext) : 0; size_t new_len, oldname_len, phar_ext_len; @@ -2200,6 +2200,8 @@ its_ok: phar_flush(phar, 0, 0, 1, &error); if (error) { + zend_hash_str_del(&(PHAR_G(phar_fname_map)), newpath, phar->fname_len); + *sphar = NULL; zend_throw_exception_ex(spl_ce_BadMethodCallException, 0, "%s", error); efree(error); efree(oldpath); diff --git a/ext/phar/tests/bug71488.phpt b/ext/phar/tests/bug71488.phpt index 9c58d89488..7f8f6c00af 100644 --- a/ext/phar/tests/bug71488.phpt +++ b/ext/phar/tests/bug71488.phpt @@ -15,4 +15,7 @@ DONE ?> --EXPECTF-- Fatal error: Uncaught BadMethodCallException: tar-based phar "%s/bug71488.test" cannot be created, link "%s" is too long for format in %sbug71488.php:%d -Stack trace:%A
\ No newline at end of file +Stack trace: +#0 %s(%d): PharData->decompress('test') +#1 {main} + thrown in %s on line %d |