From: ryosuke_i_628 at yahoo dot co dot jp
Operating system: Irrelevant
PHP version: 7.0.3
Package: cURL related
Bug Type: Bug
Bug description:Copied handle with new option CURLOPT_HTTPHEADER crashes while curl_multi_exec.
Description:
------------
Copied handle yielded by curl_copy_handle() with new option
CURLOPT_HTTPHEADER crashes while curl_multi_exec() running. The test
script causes segmentation fault in libcurl.
However, there are no problems with the following native C code. I
suppose this is a PHP bug.
#include <stdio.h>
#include <curl/curl.h>
void set_header(CURL *ch) {
struct curl_slist *headers = NULL;
headers = curl_slist_append(headers, "Foo: Bar");
curl_easy_setopt(ch, CURLOPT_HTTPHEADER, headers);
}
int main(void) {
CURL *ch_base, *ch_x, *ch_y;
CURLM *mh;
int active;
mh = curl_multi_init();
ch_base = curl_easy_init();
curl_easy_setopt(ch_base, CURLOPT_URL, "http://example.com/");
ch_x = curl_easy_duphandle(ch_base);
set_header(ch_x);
curl_multi_add_handle(mh, ch_x);
ch_y = curl_easy_duphandle(ch_base);
set_header(ch_y);
curl_multi_add_handle(mh, ch_y);
do {
curl_multi_perform(mh, &active);
} while (active);
return 0;
}
Test script:
---------------
<?php
$base = curl_init('http://example.com/');
$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);
?>
Expected result:
----------------
No errors.
Actual result:
--------------
Segmentation fault.
Stack trace with gdb:
#0 0x00000001010ddc6a in Curl_raw_nequal () from
/usr/local/opt/curl/lib/libcurl.4.dylib
#1 0x00000001010b81f0 in Curl_checkheaders () from
/usr/local/opt/curl/lib/libcurl.4.dylib
#2 0x00000001010b6553 in Curl_http () from
/usr/local/opt/curl/lib/libcurl.4.dylib
#3 0x00000001010c966d in Curl_do () from
/usr/local/opt/curl/lib/libcurl.4.dylib
#4 0x00000001010d7cad in multi_runsingle () from
/usr/local/opt/curl/lib/libcurl.4.dylib
#5 0x00000001010d7488 in curl_multi_perform () from
/usr/local/opt/curl/lib/libcurl.4.dylib
#6 0x000000010019e52f in zif_curl_multi_exec (execute_data=<optimized
out>, return_value=0x102216190)
at ext/curl/multi.c:240
#7 0x00000001004775f7 in ZEND_DO_ICALL_SPEC_HANDLER
(execute_data=0x1010f1c6b)
at Zend/zend_vm_execute.h:586
#8 0x00000001004428f8 in execute_ex (ex=<optimized out>) at
Zend/zend_vm_execute.h:417
#9 0x0000000100442bd9 in zend_execute (op_array=0x1010f1c6b,
return_value=<optimized out>)
at Zend/zend_vm_execute.h:458
#10 0x000000010040343b in zend_execute_scripts (type=0, retval=0x0,
file_count=206956997)
at Zend/zend.c:1428
#11 0x000000010039ede8 in php_execute_script (primary_file=0x101472e70)
at main/main.c:2471
#12 0x0000000100493c31 in do_cli (argc=<optimized out>, argv=<optimized
out>)
at sapi/cli/php_cli.c:974
#13 0x0000000100492a85 in main (argc=2, argv=0x7fff5fbff628) at
sapi/cli/php_cli.c:1345
--
Edit bug report at https://bugs.php.net/bug.php?id=71523&edit=1
--
Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=71523&r=trysnapshot54
Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=71523&r=trysnapshot55
Try a snapshot (trunk): https://bugs.php.net/fix.php?id=71523&r=trysnapshottrunk
Fixed in SVN: https://bugs.php.net/fix.php?id=71523&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=71523&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=71523&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=71523&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=71523&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=71523&r=support
Expected behavior: https://bugs.php.net/fix.php?id=71523&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=71523&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=71523&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=71523&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=71523&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=71523&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=71523&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=71523&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=71523&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=71523&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=71523&r=mysqlcfg