Skip to content

Commit c47b18a

Browse files
committed
Fix #79033: Curl timeout error with specific url and post
We must not set an empty mime structure as `CURLOPT_MIMEPOST`; instead we set it to `NULL` if `CURLOPT_POSTFIELDS` has been set to an empty array.
1 parent 27bb328 commit c47b18a

File tree

3 files changed

+36
-4
lines changed

3 files changed

+36
-4
lines changed

NEWS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ PHP NEWS
88

99
- CURL:
1010
. Implemented FR #77711 (CURLFile should support UNICODE filenames). (cmb)
11+
. Fixed bug #79033 (Curl timeout error with specific url and post). (cmb)
1112

1213
- Fileinfo:
1314
. Fixed bug #74170 (locale information change after mime_content_type).

ext/curl/interface.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2804,7 +2804,7 @@ static int _php_curl_setopt(php_curl *ch, zend_long option, zval *zvalue) /* {{{
28042804
zend_string *string_key;
28052805
zend_ulong num_key;
28062806
#if LIBCURL_VERSION_NUM >= 0x073800 /* 7.56.0 */
2807-
curl_mime *mime;
2807+
curl_mime *mime = NULL;
28082808
curl_mimepart *part;
28092809
CURLcode form_error;
28102810
#else
@@ -2819,9 +2819,11 @@ static int _php_curl_setopt(php_curl *ch, zend_long option, zval *zvalue) /* {{{
28192819
}
28202820

28212821
#if LIBCURL_VERSION_NUM >= 0x073800 /* 7.56.0 */
2822-
mime = curl_mime_init(ch->cp);
2823-
if (mime == NULL) {
2824-
return FAILURE;
2822+
if (zend_hash_num_elements(postfields) > 0) {
2823+
mime = curl_mime_init(ch->cp);
2824+
if (mime == NULL) {
2825+
return FAILURE;
2826+
}
28252827
}
28262828
#endif
28272829

ext/curl/tests/bug79033.phpt

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
--TEST--
2+
Bug #79033 (Curl timeout error with specific url and post)
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_URL => "{$host}/get.inc?test=post",
12+
CURLOPT_POST => true,
13+
CURLOPT_POSTFIELDS => [],
14+
CURLINFO_HEADER_OUT => true,
15+
CURLOPT_RETURNTRANSFER => true,
16+
]);
17+
var_dump(curl_exec($ch));
18+
var_dump(curl_getinfo($ch)["request_header"]);
19+
?>
20+
--EXPECTF--
21+
string(%d) "array(0) {
22+
}
23+
"
24+
string(90) "POST /get.inc?test=post HTTP/1.1
25+
Host: localhost:%d
26+
Accept: */*
27+
Content-Length: 0
28+
29+
"

0 commit comments

Comments
 (0)