Skip to content

Fix multi-same-name-fields in Curl for old (> 7.56.0) versions #8460

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions ext/curl/interface.c
Original file line number Diff line number Diff line change
Expand Up @@ -2061,15 +2061,17 @@ static void free_cb(void *arg) /* {{{ */
/* }}} */
#endif

#if LIBCURL_VERSION_NUM >= 0x073800 /* 7.56.0 */
static inline CURLcode add_simple_field(curl_mime *mime, zend_string *string_key, zval *current)
#else
static inline CURLcode add_simple_field(struct HttpPost **first, struct HttpPost **last, zend_string *string_key, zval *current)
#endif
{
CURLcode error = CURLE_OK;
#if LIBCURL_VERSION_NUM >= 0x073800 /* 7.56.0 */
curl_mimepart *part;
CURLcode form_error;
#else
struct HttpPost *first = NULL;
struct HttpPost *last = NULL;
CURLFORMcode form_error;
#endif
zend_string *postval, *tmp_postval;
Expand All @@ -2091,7 +2093,7 @@ static inline CURLcode add_simple_field(curl_mime *mime, zend_string *string_key
/* The arguments after _NAMELENGTH and _CONTENTSLENGTH
* must be explicitly cast to long in curl_formadd
* use since curl needs a long not an int. */
form_error = curl_formadd(&first, &last,
form_error = curl_formadd(first, last,
CURLFORM_COPYNAME, ZSTR_VAL(string_key),
CURLFORM_NAMELENGTH, ZSTR_LEN(string_key),
CURLFORM_COPYCONTENTS, ZSTR_VAL(postval),
Expand Down Expand Up @@ -2303,14 +2305,22 @@ static inline zend_result build_mime_structure_from_hash(php_curl *ch, zval *zpo
zval *current_element;

ZEND_HASH_FOREACH_VAL(HASH_OF(current), current_element) {
#if LIBCURL_VERSION_NUM >= 0x073800 /* 7.56.0 */
add_simple_field(mime, string_key, current_element);
#else
add_simple_field(&first, &last, string_key, current_element);
#endif
} ZEND_HASH_FOREACH_END();

zend_string_release_ex(string_key, 0);
continue;
}

#if LIBCURL_VERSION_NUM >= 0x073800 /* 7.56.0 */
add_simple_field(mime, string_key, current);
#else
add_simple_field(&first, &last, string_key, current);
#endif

zend_string_release_ex(string_key, 0);
} ZEND_HASH_FOREACH_END();
Expand Down
1 change: 1 addition & 0 deletions ext/curl/tests/curl_postfields_array.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ $options = [
CURLOPT_FORBID_REUSE => 1,
CURLOPT_TIMEOUT => 1,
CURLOPT_POSTFIELDS => $fields,
CURLOPT_HTTPHEADER => [ 'Expect:' ],
];

$ch = curl_init();
Expand Down