Skip to content

Commit 8206de6

Browse files
committed
Merge branch 'PHP-8.3' into PHP-8.4
* PHP-8.3: Fix various memory leaks in curl mime handling
2 parents d31de85 + 8906021 commit 8206de6

File tree

2 files changed

+23
-15
lines changed

2 files changed

+23
-15
lines changed

NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ PHP NEWS
77
skipLazyInitialization() may change initialized proxy). (Arnaud)
88
. Fix is_zend_ptr() huge block comparison. (nielsdos)
99

10+
- Curl:
11+
. Fix various memory leaks in curl mime handling. (nielsdos)
12+
1013
- DOM:
1114
. Fixed bug GH-16906 (Reloading document can cause UAF in iterator).
1215
(nielsdos)

ext/curl/interface.c

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1438,7 +1438,7 @@ static inline zend_result build_mime_structure_from_hash(php_curl *ch, zval *zpo
14381438
postval = Z_STR_P(prop);
14391439

14401440
if (php_check_open_basedir(ZSTR_VAL(postval))) {
1441-
return FAILURE;
1441+
goto out_string;
14421442
}
14431443

14441444
prop = zend_read_property(curl_CURLFile_class, Z_OBJ_P(current), "mime", sizeof("mime")-1, 0, &rv);
@@ -1463,15 +1463,18 @@ static inline zend_result build_mime_structure_from_hash(php_curl *ch, zval *zpo
14631463
seekfunc = NULL;
14641464
}
14651465

1466+
part = curl_mime_addpart(mime);
1467+
if (part == NULL) {
1468+
if (stream) {
1469+
php_stream_close(stream);
1470+
}
1471+
goto out_string;
1472+
}
1473+
14661474
cb_arg = emalloc(sizeof *cb_arg);
14671475
cb_arg->filename = zend_string_copy(postval);
14681476
cb_arg->stream = stream;
14691477

1470-
part = curl_mime_addpart(mime);
1471-
if (part == NULL) {
1472-
zend_string_release_ex(string_key, 0);
1473-
return FAILURE;
1474-
}
14751478
if ((form_error = curl_mime_name(part, ZSTR_VAL(string_key))) != CURLE_OK
14761479
|| (form_error = curl_mime_data_cb(part, filesize, read_cb, seekfunc, free_cb, cb_arg)) != CURLE_OK
14771480
|| (form_error = curl_mime_filename(part, filename ? filename : ZSTR_VAL(postval))) != CURLE_OK
@@ -1492,8 +1495,7 @@ static inline zend_result build_mime_structure_from_hash(php_curl *ch, zval *zpo
14921495

14931496
prop = zend_read_property(curl_CURLStringFile_class, Z_OBJ_P(current), "postname", sizeof("postname")-1, 0, &rv);
14941497
if (EG(exception)) {
1495-
zend_string_release_ex(string_key, 0);
1496-
return FAILURE;
1498+
goto out_string;
14971499
}
14981500
ZVAL_DEREF(prop);
14991501
ZEND_ASSERT(Z_TYPE_P(prop) == IS_STRING);
@@ -1502,8 +1504,7 @@ static inline zend_result build_mime_structure_from_hash(php_curl *ch, zval *zpo
15021504

15031505
prop = zend_read_property(curl_CURLStringFile_class, Z_OBJ_P(current), "mime", sizeof("mime")-1, 0, &rv);
15041506
if (EG(exception)) {
1505-
zend_string_release_ex(string_key, 0);
1506-
return FAILURE;
1507+
goto out_string;
15071508
}
15081509
ZVAL_DEREF(prop);
15091510
ZEND_ASSERT(Z_TYPE_P(prop) == IS_STRING);
@@ -1512,8 +1513,7 @@ static inline zend_result build_mime_structure_from_hash(php_curl *ch, zval *zpo
15121513

15131514
prop = zend_read_property(curl_CURLStringFile_class, Z_OBJ_P(current), "data", sizeof("data")-1, 0, &rv);
15141515
if (EG(exception)) {
1515-
zend_string_release_ex(string_key, 0);
1516-
return FAILURE;
1516+
goto out_string;
15171517
}
15181518
ZVAL_DEREF(prop);
15191519
ZEND_ASSERT(Z_TYPE_P(prop) == IS_STRING);
@@ -1525,8 +1525,7 @@ static inline zend_result build_mime_structure_from_hash(php_curl *ch, zval *zpo
15251525

15261526
part = curl_mime_addpart(mime);
15271527
if (part == NULL) {
1528-
zend_string_release_ex(string_key, 0);
1529-
return FAILURE;
1528+
goto out_string;
15301529
}
15311530
if ((form_error = curl_mime_name(part, ZSTR_VAL(string_key))) != CURLE_OK
15321531
|| (form_error = curl_mime_data(part, ZSTR_VAL(postval), ZSTR_LEN(postval))) != CURLE_OK
@@ -1557,7 +1556,7 @@ static inline zend_result build_mime_structure_from_hash(php_curl *ch, zval *zpo
15571556

15581557
SAVE_CURL_ERROR(ch, error);
15591558
if (error != CURLE_OK) {
1560-
return FAILURE;
1559+
goto out_mime;
15611560
}
15621561

15631562
if ((*ch->clone) == 1) {
@@ -1568,6 +1567,12 @@ static inline zend_result build_mime_structure_from_hash(php_curl *ch, zval *zpo
15681567

15691568
SAVE_CURL_ERROR(ch, error);
15701569
return error == CURLE_OK ? SUCCESS : FAILURE;
1570+
1571+
out_string:
1572+
zend_string_release_ex(string_key, false);
1573+
out_mime:
1574+
curl_mime_free(mime);
1575+
return FAILURE;
15711576
}
15721577
/* }}} */
15731578

0 commit comments

Comments
 (0)