]> granicus.if.org Git - php/commitdiff
Fix segfault when using curl_copy_handle with CURLOPT_PROGRESSFUNCTION
authorPierrick Charron <pierrick@php.net>
Sun, 4 Dec 2011 01:16:17 +0000 (01:16 +0000)
committerPierrick Charron <pierrick@php.net>
Sun, 4 Dec 2011 01:16:17 +0000 (01:16 +0000)
ext/curl/interface.c
ext/curl/tests/curl_copy_handle_basic_008.phpt [new file with mode: 0644]

index c2a6f6da983a4aeadf9b2219ac710ec5a0884c08..6eb1fa94c2420ee4ad9a7224aafb30c35cb181f1 100644 (file)
@@ -1965,6 +1965,26 @@ PHP_FUNCTION(curl_copy_handle)
        curl_easy_setopt(dupch->cp, CURLOPT_INFILE,            (void *) dupch);
        curl_easy_setopt(dupch->cp, CURLOPT_WRITEHEADER,       (void *) dupch);
 
+       if (ch->handlers->progress) {
+               dupch->handlers->progress = ecalloc(1, sizeof(php_curl_progress));
+               if (ch->handlers->progress->func_name) {
+                       zval_add_ref(&ch->handlers->progress->func_name);
+                       dupch->handlers->progress->func_name = ch->handlers->progress->func_name;
+               }
+               dupch->handlers->progress->method = ch->handlers->progress->method;
+               curl_easy_setopt(dupch->cp, CURLOPT_PROGRESSDATA, (void *) dupch);
+       }
+
+       if (ch->handlers->fnmatch) {
+               dupch->handlers->fnmatch = ecalloc(1, sizeof(php_curl_fnmatch));
+               if (ch->handlers->fnmatch->func_name) {
+                       zval_add_ref(&ch->handlers->fnmatch->func_name);
+                       dupch->handlers->fnmatch->func_name = ch->handlers->fnmatch->func_name;
+               }   
+               dupch->handlers->fnmatch->method = ch->handlers->fnmatch->method;
+               curl_easy_setopt(dupch->cp, CURLOPT_FNMATCH_DATA, (void *) dupch);
+       }
+
        efree(dupch->to_free);
        dupch->to_free = ch->to_free;
 
diff --git a/ext/curl/tests/curl_copy_handle_basic_008.phpt b/ext/curl/tests/curl_copy_handle_basic_008.phpt
new file mode 100644 (file)
index 0000000..692c2df
--- /dev/null
@@ -0,0 +1,25 @@
+--TEST--
+Test curl_copy_handle() with CURLOPT_PROGRESSFUNCTION
+--SKIPIF--
+<?php if (!extension_loaded("curl") || false === getenv('PHP_CURL_HTTP_REMOTE_SERVER')) print "skip need PHP_CURL_HTTP_REMOTE_SERVER environment variable"; ?>
+--FILE--
+<?php
+  $host = getenv('PHP_CURL_HTTP_REMOTE_SERVER');
+
+  $url = "{$host}/get.php";
+  $ch = curl_init($url);
+
+  curl_setopt($ch, CURLOPT_NOPROGRESS, 0);
+  curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
+  curl_setopt($ch, CURLOPT_PROGRESSFUNCTION, function() { });
+  $ch2 = curl_copy_handle($ch);
+  echo curl_exec($ch), PHP_EOL;
+  unset($ch);
+  echo curl_exec($ch2);
+
+?>
+--EXPECTF--
+Hello World!
+Hello World!
+Hello World!
+Hello World!