summaryrefslogtreecommitdiff
path: root/ext/curl
diff options
context:
space:
mode:
authorChristoph M. Becker <cmbecker69@gmx.de>2019-12-28 10:47:03 +0100
committerChristoph M. Becker <cmbecker69@gmx.de>2019-12-28 10:47:03 +0100
commitc47b18a222ceb1d78810d2822170cbf6e110a98c (patch)
tree5602e99e79caf706f5b9e8777a896e5758545cd5 /ext/curl
parent27bb3289aceb5225e4dd39f082a48823756a8190 (diff)
downloadphp-git-c47b18a222ceb1d78810d2822170cbf6e110a98c.tar.gz
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.
Diffstat (limited to 'ext/curl')
-rw-r--r--ext/curl/interface.c10
-rw-r--r--ext/curl/tests/bug79033.phpt29
2 files changed, 35 insertions, 4 deletions
diff --git a/ext/curl/interface.c b/ext/curl/interface.c
index 313743b62b..0772b3a522 100644
--- a/ext/curl/interface.c
+++ b/ext/curl/interface.c
@@ -2804,7 +2804,7 @@ static int _php_curl_setopt(php_curl *ch, zend_long option, zval *zvalue) /* {{{
zend_string *string_key;
zend_ulong num_key;
#if LIBCURL_VERSION_NUM >= 0x073800 /* 7.56.0 */
- curl_mime *mime;
+ curl_mime *mime = NULL;
curl_mimepart *part;
CURLcode form_error;
#else
@@ -2819,9 +2819,11 @@ static int _php_curl_setopt(php_curl *ch, zend_long option, zval *zvalue) /* {{{
}
#if LIBCURL_VERSION_NUM >= 0x073800 /* 7.56.0 */
- mime = curl_mime_init(ch->cp);
- if (mime == NULL) {
- return FAILURE;
+ if (zend_hash_num_elements(postfields) > 0) {
+ mime = curl_mime_init(ch->cp);
+ if (mime == NULL) {
+ return FAILURE;
+ }
}
#endif
diff --git a/ext/curl/tests/bug79033.phpt b/ext/curl/tests/bug79033.phpt
new file mode 100644
index 0000000000..98a97ed7a4
--- /dev/null
+++ b/ext/curl/tests/bug79033.phpt
@@ -0,0 +1,29 @@
+--TEST--
+Bug #79033 (Curl timeout error with specific url and post)
+--SKIPIF--
+<?php include 'skipif.inc'; ?>
+--FILE--
+<?php
+include 'server.inc';
+$host = curl_cli_server_start();
+$ch = curl_init();
+curl_setopt_array($ch, [
+ CURLOPT_URL => "{$host}/get.inc?test=post",
+ CURLOPT_POST => true,
+ CURLOPT_POSTFIELDS => [],
+ CURLINFO_HEADER_OUT => true,
+ CURLOPT_RETURNTRANSFER => true,
+]);
+var_dump(curl_exec($ch));
+var_dump(curl_getinfo($ch)["request_header"]);
+?>
+--EXPECTF--
+string(%d) "array(0) {
+}
+"
+string(90) "POST /get.inc?test=post HTTP/1.1
+Host: localhost:%d
+Accept: */*
+Content-Length: 0
+
+"