Skip to content

Commit 33718fb

Browse files
committed
Merge branch 'PHP-8.3' into PHP-8.4
* PHP-8.3: phar: Fix memory leaks when creating temp file fails when applying zip signature
2 parents f2f84e3 + 66c8334 commit 33718fb

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
@@ -44,6 +44,8 @@ PHP NEWS
4444
- Phar:
4545
. Fix memory leak and invalid continuation after tar header writing fails.
4646
(nielsdos)
47+
. Fix memory leaks when creating temp file fails when applying zip signature.
48+
(nielsdos)
4749

4850
- SimpleXML:
4951
. 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
@@ -1223,7 +1223,9 @@ static int phar_zip_applysignature(phar_archive_data *phar, struct _phar_zip_pas
12231223
entry.fp_type = PHAR_MOD;
12241224
entry.is_modified = 1;
12251225
if (entry.fp == NULL) {
1226+
efree(signature);
12261227
spprintf(pass->error, 0, "phar error: unable to create temporary file for signature");
1228+
php_stream_close(newfile);
12271229
return FAILURE;
12281230
}
12291231

@@ -1441,11 +1443,12 @@ void phar_zip_flush(phar_archive_data *phar, zend_string *user_stub, bool is_def
14411443

14421444
phar_metadata_tracker_try_ensure_has_serialized_data(&phar->metadata_tracker, phar->is_persistent);
14431445
if (temperr) {
1446+
temperror:
14441447
if (error) {
14451448
spprintf(error, 4096, "phar zip flush of \"%s\" failed: %s", phar->fname, temperr);
14461449
}
14471450
efree(temperr);
1448-
temperror:
1451+
notemperror:
14491452
php_stream_close(pass.centralfp);
14501453
nocentralerror:
14511454
php_stream_close(pass.filefp);
@@ -1473,7 +1476,7 @@ void phar_zip_flush(phar_archive_data *phar, zend_string *user_stub, bool is_def
14731476
if (error) {
14741477
spprintf(error, 4096, "phar zip flush of \"%s\" failed: unable to write central-directory", phar->fname);
14751478
}
1476-
goto temperror;
1479+
goto notemperror;
14771480
}
14781481
}
14791482

0 commit comments

Comments
 (0)