Skip to content

Commit

Permalink
Fix #77919: Potential UAF in Phar RSHUTDOWN
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
cmb69 authored and smalyshev committed Jul 29, 2019
1 parent 42e8b85 commit cd1101e
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
3 changes: 3 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ PHP NEWS
(CVE-2019-11042) (Stas)
. Fixed bug #78222 (heap-buffer-overflow on exif_scan_thumbnail).
(CVE-2019-11041) (Stas)

- Phar:
. Fixed bug #77919 (Potential UAF in Phar RSHUTDOWN). (cmb)

30 May 2019, PHP 7.1.30

Expand Down
4 changes: 3 additions & 1 deletion ext/phar/phar_object.c
Original file line number Diff line number Diff line change
Expand Up @@ -2037,7 +2037,7 @@ static zend_object *phar_rename_archive(phar_archive_data **sphar, char *ext, ze
char *newname = NULL, *newpath = NULL;
zval ret, arg1;
zend_class_entry *ce;
char *error;
char *error = NULL;
const char *pcr_error;
int ext_len = ext ? strlen(ext) : 0;
size_t new_len, oldname_len;
Expand Down Expand Up @@ -2205,6 +2205,8 @@ static zend_object *phar_rename_archive(phar_archive_data **sphar, char *ext, ze
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);
Expand Down
5 changes: 4 additions & 1 deletion ext/phar/tests/bug71488.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Stack trace:
#0 %s(%d): PharData->decompress('test')
#1 {main}
thrown in %s on line %d

0 comments on commit cd1101e

Please sign in to comment.