Skip to content

Commit c321896

Browse files
committed
Merge branch 'PHP-7.4' into PHP-8.0
* PHP-7.4: Fix #80595: Resetting POSTFIELDS to empty array breaks request
2 parents 880bf62 + 38ad37a commit c321896

File tree

4 files changed

+42
-1
lines changed

4 files changed

+42
-1
lines changed

NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ PHP NEWS
1515
. Fixed bug #80545 (bcadd('a', 'a') doesn't throw an exception).
1616
(Jens de Nies)
1717

18+
- Curl:
19+
. Fixed bug #80595 (Resetting POSTFIELDS to empty array breaks request). (cmb)
20+
1821
- Date:
1922
. Fixed bug #80376 (last day of the month causes runway cpu usage). (Derick)
2023

ext/curl/interface.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2722,7 +2722,14 @@ static int _php_curl_setopt(php_curl *ch, zend_long option, zval *zvalue, bool i
27222722

27232723
case CURLOPT_POSTFIELDS:
27242724
if (Z_TYPE_P(zvalue) == IS_ARRAY) {
2725-
return build_mime_structure_from_hash(ch, zvalue);
2725+
if (zend_hash_num_elements(HASH_OF(zvalue)) == 0) {
2726+
/* no need to build the mime structure for empty hashtables;
2727+
also works around https://github.com/curl/curl/issues/6455 */
2728+
curl_easy_setopt(ch->cp, CURLOPT_POSTFIELDS, "");
2729+
error = curl_easy_setopt(ch->cp, CURLOPT_POSTFIELDSIZE, 0);
2730+
} else {
2731+
return build_mime_structure_from_hash(ch, zvalue);
2732+
}
27262733
} else {
27272734
zend_string *tmp_str;
27282735
zend_string *str = zval_get_tmp_string(zvalue, &tmp_str);

ext/curl/tests/bug79033.phpt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,6 @@ string(%d) "POST /get.inc?test=post HTTP/1.1
2525
Host: localhost:%d
2626
Accept: */*
2727
Content-Length: 0
28+
Content-Type: application/x-www-form-urlencoded
2829

2930
"

ext/curl/tests/bug80595.phpt

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
--TEST--
2+
Bug #80595 (Resetting POSTFIELDS to empty array breaks request)
3+
--SKIPIF--
4+
<?php include 'skipif.inc'; ?>
5+
--FILE--
6+
<?php
7+
include 'server.inc';
8+
$host = curl_cli_server_start();
9+
$ch = curl_init();
10+
curl_setopt_array($ch, [
11+
CURLOPT_RETURNTRANSFER => true,
12+
CURLOPT_POST => true,
13+
CURLOPT_URL => "{$host}/get.inc?test=post",
14+
]);
15+
16+
curl_setopt($ch, CURLOPT_POSTFIELDS, ['foo' => 'bar']);
17+
var_dump(curl_exec($ch));
18+
19+
curl_setopt($ch, CURLOPT_POSTFIELDS, []);
20+
var_dump(curl_exec($ch));
21+
?>
22+
--EXPECT--
23+
string(43) "array(1) {
24+
["foo"]=>
25+
string(3) "bar"
26+
}
27+
"
28+
string(13) "array(0) {
29+
}
30+
"

0 commit comments

Comments
 (0)