Skip to content

Commit a0dd445

Browse files
committed
Fix the bug where clone curl does not copy POST fields
1 parent 96ac2c4 commit a0dd445

File tree

2 files changed

+48
-1
lines changed

2 files changed

+48
-1
lines changed

ext/curl/interface.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1310,6 +1310,7 @@ void _php_setup_easy_copy_handlers(php_curl *ch, php_curl *source)
13101310
#endif
13111311

13121312
ZVAL_COPY(&ch->private_data, &source->private_data);
1313+
ZVAL_COPY(&ch->postfields, &source->postfields);
13131314

13141315
efree(ch->to_free);
13151316
ch->to_free = source->to_free;
@@ -1595,7 +1596,7 @@ PHP_FUNCTION(curl_copy_handle)
15951596

15961597
_php_setup_easy_copy_handlers(dupch, ch);
15971598

1598-
postfields = &ch->postfields;
1599+
postfields = &dupch->postfields;
15991600
if (Z_TYPE_P(postfields) != IS_UNDEF) {
16001601
if (build_mime_structure_from_hash(dupch, postfields) == FAILURE) {
16011602
zval_ptr_dtor(return_value);
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
--TEST--
2+
Test that cloning of Curl object post CURLFile multiple times with curl_multi_exec()
3+
--EXTENSIONS--
4+
curl
5+
--FILE--
6+
<?php
7+
include 'server.inc';
8+
$host = curl_cli_server_start();
9+
10+
$ch1 = curl_init();
11+
curl_setopt($ch1, CURLOPT_SAFE_UPLOAD, 1);
12+
curl_setopt($ch1, CURLOPT_URL, "{$host}/get.php?test=file");
13+
// curl_setopt($ch1, CURLOPT_RETURNTRANSFER, 1);
14+
15+
$filename = __DIR__ . '/curl_copy_handle_variation4.txt';
16+
file_put_contents($filename, "Test.");
17+
$file = curl_file_create($filename);
18+
$params = array('file' => $file);
19+
var_dump(curl_setopt($ch1, CURLOPT_POSTFIELDS, $params));
20+
21+
$ch2 = clone $ch1;
22+
$ch3 = clone $ch1;
23+
24+
$mh = curl_multi_init();
25+
curl_multi_add_handle($mh, $ch1);
26+
curl_multi_add_handle($mh, $ch2);
27+
do {
28+
$status = curl_multi_exec($mh, $active);
29+
if ($active) {
30+
curl_multi_select($mh);
31+
}
32+
} while ($active && $status == CURLM_OK);
33+
34+
curl_multi_remove_handle($mh, $ch1);
35+
curl_multi_remove_handle($mh, $ch2);
36+
curl_multi_remove_handle($mh, $ch3);
37+
curl_multi_close($mh);
38+
?>
39+
===DONE===
40+
--EXPECT--
41+
bool(true)
42+
curl_copy_handle_variation4.txt|application/octet-stream|5curl_copy_handle_variation4.txt|application/octet-stream|5===DONE===
43+
--CLEAN--
44+
<?php
45+
@unlink(__DIR__ . '/curl_copy_handle_variation4.txt');
46+
?>

0 commit comments

Comments
 (0)