]> granicus.if.org Git - php/commitdiff
Fix #79033: Curl timeout error with specific url and post
authorChristoph M. Becker <cmbecker69@gmx.de>
Sat, 28 Dec 2019 09:47:03 +0000 (10:47 +0100)
committerChristoph M. Becker <cmbecker69@gmx.de>
Sat, 28 Dec 2019 09:47:03 +0000 (10:47 +0100)
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.

NEWS
ext/curl/interface.c
ext/curl/tests/bug79033.phpt [new file with mode: 0644]

diff --git a/NEWS b/NEWS
index b11b87830a9d2748e66c14b4556c61b47e712f34..afd39b7dded7436ad3689ca4abbd0fa64c52a4ef 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -8,6 +8,7 @@ PHP                                                                        NEWS
 
 - CURL:
   . Implemented FR #77711 (CURLFile should support UNICODE filenames). (cmb)
+  . Fixed bug #79033 (Curl timeout error with specific url and post). (cmb)
 
 - Fileinfo:
   . Fixed bug #74170 (locale information change after mime_content_type).
index 313743b62b6d78d6540b75dc4cf9b4ff4904bd82..0772b3a5222e53ef0566fdbab84ca3e36cde1f22 100644 (file)
@@ -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 (file)
index 0000000..98a97ed
--- /dev/null
@@ -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
+
+"