Skip to content

Commit 5a7c84f

Browse files
committed
phar: Fix memleak+UAF when opening temp stream in buildFromDirectory() fails
Obvious memleak, but can also cause a UAF depending on destruction ordering with lingering PCRE regex instances in the SPL objects. Closes phpGH-20157.
1 parent b529c77 commit 5a7c84f

File tree

2 files changed

+6
-0
lines changed

2 files changed

+6
-0
lines changed

NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ PHP NEWS
3131
. Fix a bunch of memory leaks in phar_parse_zipfile() error handling.
3232
(nielsdos)
3333
. Fix file descriptor/memory leak when opening central fp fails. (nielsdos)
34+
. Fix memleak+UAF when opening temp stream in buildFromDirectory() fails.
35+
(nielsdos)
3436

3537
- Random:
3638
. Fix Randomizer::__serialize() w.r.t. INDIRECTs. (nielsdos)

ext/phar/phar_object.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1784,6 +1784,10 @@ PHP_METHOD(Phar, buildFromDirectory)
17841784
pass.ret = return_value;
17851785
pass.fp = php_stream_fopen_tmpfile();
17861786
if (pass.fp == NULL) {
1787+
zval_ptr_dtor(&iteriter);
1788+
if (apply_reg) {
1789+
zval_ptr_dtor(&regexiter);
1790+
}
17871791
zend_throw_exception_ex(phar_ce_PharException, 0, "phar \"%s\" unable to create temporary file", phar_obj->archive->fname);
17881792
RETURN_THROWS();
17891793
}

0 commit comments

Comments
 (0)