Skip to content

Commit d84e1b5

Browse files
committed
Fix segfault when using curl_copy_handle with CURLOPT_PROGRESSFUNCTION
1 parent 8253bdb commit d84e1b5

File tree

2 files changed

+45
-0
lines changed

2 files changed

+45
-0
lines changed

ext/curl/interface.c

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1965,6 +1965,26 @@ PHP_FUNCTION(curl_copy_handle)
19651965
curl_easy_setopt(dupch->cp, CURLOPT_INFILE, (void *) dupch);
19661966
curl_easy_setopt(dupch->cp, CURLOPT_WRITEHEADER, (void *) dupch);
19671967

1968+
if (ch->handlers->progress) {
1969+
dupch->handlers->progress = ecalloc(1, sizeof(php_curl_progress));
1970+
if (ch->handlers->progress->func_name) {
1971+
zval_add_ref(&ch->handlers->progress->func_name);
1972+
dupch->handlers->progress->func_name = ch->handlers->progress->func_name;
1973+
}
1974+
dupch->handlers->progress->method = ch->handlers->progress->method;
1975+
curl_easy_setopt(dupch->cp, CURLOPT_PROGRESSDATA, (void *) dupch);
1976+
}
1977+
1978+
if (ch->handlers->fnmatch) {
1979+
dupch->handlers->fnmatch = ecalloc(1, sizeof(php_curl_fnmatch));
1980+
if (ch->handlers->fnmatch->func_name) {
1981+
zval_add_ref(&ch->handlers->fnmatch->func_name);
1982+
dupch->handlers->fnmatch->func_name = ch->handlers->fnmatch->func_name;
1983+
}
1984+
dupch->handlers->fnmatch->method = ch->handlers->fnmatch->method;
1985+
curl_easy_setopt(dupch->cp, CURLOPT_FNMATCH_DATA, (void *) dupch);
1986+
}
1987+
19681988
efree(dupch->to_free);
19691989
dupch->to_free = ch->to_free;
19701990

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
--TEST--
2+
Test curl_copy_handle() with CURLOPT_PROGRESSFUNCTION
3+
--SKIPIF--
4+
<?php if (!extension_loaded("curl") || false === getenv('PHP_CURL_HTTP_REMOTE_SERVER')) print "skip need PHP_CURL_HTTP_REMOTE_SERVER environment variable"; ?>
5+
--FILE--
6+
<?php
7+
$host = getenv('PHP_CURL_HTTP_REMOTE_SERVER');
8+
9+
$url = "{$host}/get.php";
10+
$ch = curl_init($url);
11+
12+
curl_setopt($ch, CURLOPT_NOPROGRESS, 0);
13+
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
14+
curl_setopt($ch, CURLOPT_PROGRESSFUNCTION, function() { });
15+
$ch2 = curl_copy_handle($ch);
16+
echo curl_exec($ch), PHP_EOL;
17+
unset($ch);
18+
echo curl_exec($ch2);
19+
20+
?>
21+
--EXPECTF--
22+
Hello World!
23+
Hello World!
24+
Hello World!
25+
Hello World!

0 commit comments

Comments
 (0)