Skip to content

Commit 4591f04

Browse files
committed
Merge branch 'PHP-8.4'
* PHP-8.4: Fix various memory leaks in curl mime handling
2 parents be27cbd + 8206de6 commit 4591f04

File tree

1 file changed

+20
-15
lines changed

1 file changed

+20
-15
lines changed

ext/curl/interface.c

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

14381438
if (php_check_open_basedir(ZSTR_VAL(postval))) {
1439-
return FAILURE;
1439+
goto out_string;
14401440
}
14411441

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

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

1468-
part = curl_mime_addpart(mime);
1469-
if (part == NULL) {
1470-
zend_string_release_ex(string_key, 0);
1471-
return FAILURE;
1472-
}
14731476
if ((form_error = curl_mime_name(part, ZSTR_VAL(string_key))) != CURLE_OK
14741477
|| (form_error = curl_mime_data_cb(part, filesize, read_cb, seekfunc, free_cb, cb_arg)) != CURLE_OK
14751478
|| (form_error = curl_mime_filename(part, filename ? filename : ZSTR_VAL(postval))) != CURLE_OK
@@ -1490,8 +1493,7 @@ static inline zend_result build_mime_structure_from_hash(php_curl *ch, zval *zpo
14901493

14911494
prop = zend_read_property(curl_CURLStringFile_class, Z_OBJ_P(current), "postname", sizeof("postname")-1, 0, &rv);
14921495
if (EG(exception)) {
1493-
zend_string_release_ex(string_key, 0);
1494-
return FAILURE;
1496+
goto out_string;
14951497
}
14961498
ZVAL_DEREF(prop);
14971499
ZEND_ASSERT(Z_TYPE_P(prop) == IS_STRING);
@@ -1500,8 +1502,7 @@ static inline zend_result build_mime_structure_from_hash(php_curl *ch, zval *zpo
15001502

15011503
prop = zend_read_property(curl_CURLStringFile_class, Z_OBJ_P(current), "mime", sizeof("mime")-1, 0, &rv);
15021504
if (EG(exception)) {
1503-
zend_string_release_ex(string_key, 0);
1504-
return FAILURE;
1505+
goto out_string;
15051506
}
15061507
ZVAL_DEREF(prop);
15071508
ZEND_ASSERT(Z_TYPE_P(prop) == IS_STRING);
@@ -1510,8 +1511,7 @@ static inline zend_result build_mime_structure_from_hash(php_curl *ch, zval *zpo
15101511

15111512
prop = zend_read_property(curl_CURLStringFile_class, Z_OBJ_P(current), "data", sizeof("data")-1, 0, &rv);
15121513
if (EG(exception)) {
1513-
zend_string_release_ex(string_key, 0);
1514-
return FAILURE;
1514+
goto out_string;
15151515
}
15161516
ZVAL_DEREF(prop);
15171517
ZEND_ASSERT(Z_TYPE_P(prop) == IS_STRING);
@@ -1523,8 +1523,7 @@ static inline zend_result build_mime_structure_from_hash(php_curl *ch, zval *zpo
15231523

15241524
part = curl_mime_addpart(mime);
15251525
if (part == NULL) {
1526-
zend_string_release_ex(string_key, 0);
1527-
return FAILURE;
1526+
goto out_string;
15281527
}
15291528
if ((form_error = curl_mime_name(part, ZSTR_VAL(string_key))) != CURLE_OK
15301529
|| (form_error = curl_mime_data(part, ZSTR_VAL(postval), ZSTR_LEN(postval))) != CURLE_OK
@@ -1555,7 +1554,7 @@ static inline zend_result build_mime_structure_from_hash(php_curl *ch, zval *zpo
15551554

15561555
SAVE_CURL_ERROR(ch, error);
15571556
if (error != CURLE_OK) {
1558-
return FAILURE;
1557+
goto out_mime;
15591558
}
15601559

15611560
if ((*ch->clone) == 1) {
@@ -1566,6 +1565,12 @@ static inline zend_result build_mime_structure_from_hash(php_curl *ch, zval *zpo
15661565

15671566
SAVE_CURL_ERROR(ch, error);
15681567
return error == CURLE_OK ? SUCCESS : FAILURE;
1568+
1569+
out_string:
1570+
zend_string_release_ex(string_key, false);
1571+
out_mime:
1572+
curl_mime_free(mime);
1573+
return FAILURE;
15691574
}
15701575
/* }}} */
15711576

0 commit comments

Comments
 (0)