]> granicus.if.org Git - php/commitdiff
Fixed bug #71523 (Copied handle with new option CURLOPT_HTTPHEADER crashes while...
authorXinchen Hui <laruence@gmail.com>
Fri, 5 Feb 2016 11:49:26 +0000 (19:49 +0800)
committerXinchen Hui <laruence@gmail.com>
Fri, 5 Feb 2016 11:49:26 +0000 (19:49 +0800)
NEWS
ext/curl/interface.c
ext/curl/tests/bug71523.phpt [new file with mode: 0644]

diff --git a/NEWS b/NEWS
index f3ebebae4da1c5135f9fd952b2f571e91d453fe4..0fc0565798ee0d8f4f77eb982df48089adc38a96 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -2,6 +2,10 @@ PHP                                                                        NEWS
 |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
 ?? ??? 2016, PHP 5.6.19
 
+- CURL:
+  . Fixed bug #71523 (Copied handle with new option CURLOPT_HTTPHEADER crashes
+    while curl_multi_exec). (Laruence)
+
 - Date:
   . Fixed bug #68078 (Datetime comparisons ignore microseconds). (Willem-Jan
     Zijderveld)
index 267afecd8b973d50e403c7550b5db694cf7895c8..d9aab7541c8638c12bfe0d490950c5eb158ccd4d 100644 (file)
@@ -2543,7 +2543,12 @@ static int _php_curl_setopt(php_curl *ch, long option, zval **zvalue TSRMLS_DC)
                                        return 1;
                                }
                        }
-                       zend_hash_index_update(ch->to_free->slist, (ulong) option, &slist, sizeof(struct curl_slist *), NULL);
+
+                       if (Z_REFCOUNT_P(ch->clone) <= 1) {
+                               zend_hash_index_update(ch->to_free->slist, (ulong) option, &slist, sizeof(struct curl_slist *), NULL);
+                       } else {
+                               zend_hash_next_index_insert(ch->to_free->slist, &slist, sizeof(struct curl_slist *), NULL);
+                       }
 
                        error = curl_easy_setopt(ch->cp, option, slist);
 
diff --git a/ext/curl/tests/bug71523.phpt b/ext/curl/tests/bug71523.phpt
new file mode 100644 (file)
index 0000000..06647de
--- /dev/null
@@ -0,0 +1,28 @@
+--TEST--
+Bug #71523 (Copied handle with new option CURLOPT_HTTPHEADER crashes while curl_multi_exec)
+--SKIPIF--
+<?php
+if (!extension_loaded("curl")) {
+        exit("skip curl extension not loaded");
+}
+?>
+--FILE--
+<?php
+
+$base = curl_init('http://www.google.com/');
+curl_setopt($base, CURLOPT_RETURNTRANSFER, true);
+$mh = curl_multi_init();
+
+for ($i = 0; $i < 2; ++$i) {
+       $ch = curl_copy_handle($base);
+       curl_setopt($ch, CURLOPT_HTTPHEADER, ['Foo: Bar']);
+       curl_multi_add_handle($mh, $ch);
+}
+
+do {
+       curl_multi_exec($mh, $active);
+} while ($active);
+?>
+okey
+--EXPECTF--
+okey