Skip to content

Commit 5d10a33

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

File tree

2 files changed

+47
-1
lines changed

2 files changed

+47
-1
lines changed

ext/curl/interface.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -453,7 +453,7 @@ static zend_object *curl_clone_obj(zend_object *object) {
453453
clone_ch->cp = cp;
454454
_php_setup_easy_copy_handlers(clone_ch, ch);
455455

456-
postfields = &clone_ch->postfields;
456+
postfields = &ch->postfields;
457457
if (Z_TYPE_P(postfields) != IS_UNDEF) {
458458
if (build_mime_structure_from_hash(clone_ch, postfields) == FAILURE) {
459459
zend_throw_exception(NULL, "Failed to clone CurlHandle", 0);
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)