Skip to content

Commit ad60d7d

Browse files
committed
curl: Fix cloning of POST fields
1 parent 4974d5e commit ad60d7d

File tree

2 files changed

+35
-1
lines changed

2 files changed

+35
-1
lines changed

ext/curl/interface.c

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

471-
postfields = &clone_ch->postfields;
471+
postfields = &ch->postfields;
472472
if (Z_TYPE_P(postfields) != IS_UNDEF) {
473473
if (build_mime_structure_from_hash(clone_ch, postfields) == FAILURE) {
474474
zend_throw_exception(NULL, "Failed to clone CurlHandle", 0);
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
--TEST--
2+
clone() allows to post CURLFile multiple times
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_variation3_clone.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+
23+
var_dump(curl_exec($ch1));
24+
25+
var_dump(curl_exec($ch2));
26+
?>
27+
--EXPECTF--
28+
bool(true)
29+
string(%d) "curl_copy_handle_variation3_clone.txt|application/octet-stream|5"
30+
string(%d) "curl_copy_handle_variation3_clone.txt|application/octet-stream|5"
31+
--CLEAN--
32+
<?php
33+
@unlink(__DIR__ . '/curl_copy_handle_variation3_clone.txt');
34+
?>

0 commit comments

Comments
 (0)