Skip to content

Commit 66c8334

Browse files
committed
phar: Fix memory leaks when creating temp file fails when applying zip signature
Also fixes up the error propagation at the call site which jumped to the wrong place in the error handling code. Closes phpGH-20057.
1 parent 4fed57e commit 66c8334

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ PHP NEWS
3838
- Phar:
3939
. Fix memory leak and invalid continuation after tar header writing fails.
4040
(nielsdos)
41+
. Fix memory leaks when creating temp file fails when applying zip signature.
42+
(nielsdos)
4143

4244
- SimpleXML:
4345
. Fixed bug GH-19988 (zend_string_init with NULL pointer in simplexml (UB)).

ext/phar/zip.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1192,7 +1192,9 @@ static int phar_zip_applysignature(phar_archive_data *phar, struct _phar_zip_pas
11921192
entry.fp_type = PHAR_MOD;
11931193
entry.is_modified = 1;
11941194
if (entry.fp == NULL) {
1195+
efree(signature);
11951196
spprintf(pass->error, 0, "phar error: unable to create temporary file for signature");
1197+
php_stream_close(newfile);
11961198
return FAILURE;
11971199
}
11981200

@@ -1456,11 +1458,12 @@ int phar_zip_flush(phar_archive_data *phar, char *user_stub, zend_long len, int
14561458

14571459
phar_metadata_tracker_try_ensure_has_serialized_data(&phar->metadata_tracker, phar->is_persistent);
14581460
if (temperr) {
1461+
temperror:
14591462
if (error) {
14601463
spprintf(error, 4096, "phar zip flush of \"%s\" failed: %s", phar->fname, temperr);
14611464
}
14621465
efree(temperr);
1463-
temperror:
1466+
notemperror:
14641467
php_stream_close(pass.centralfp);
14651468
nocentralerror:
14661469
php_stream_close(pass.filefp);
@@ -1488,7 +1491,7 @@ int phar_zip_flush(phar_archive_data *phar, char *user_stub, zend_long len, int
14881491
if (error) {
14891492
spprintf(error, 4096, "phar zip flush of \"%s\" failed: unable to write central-directory", phar->fname);
14901493
}
1491-
goto temperror;
1494+
goto notemperror;
14921495
}
14931496
}
14941497

0 commit comments

Comments
 (0)