]> granicus.if.org Git - php/commitdiff
Fixed bug #60439curl_copy_handle segfault when used with CURLOPT_PROGRESSFUNCTION
authorPierrick Charron <pierrick@php.net>
Sun, 4 Dec 2011 01:34:54 +0000 (01:34 +0000)
committerPierrick Charron <pierrick@php.net>
Sun, 4 Dec 2011 01:34:54 +0000 (01:34 +0000)
NEWS
ext/curl/interface.c
ext/curl/tests/curl_copy_handle_basic_008.phpt [new file with mode: 0644]

diff --git a/NEWS b/NEWS
index 0dde31877ffb6ced6f0ac18eb917e489dc198447..4056bbb77e4b2cf7ee4616eb244bf422bae1a814 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -10,6 +10,10 @@ PHP                                                                        NEWS
 - CLI SAPI:
   . Implement FR #60390 (Missing $_SERVER['SERVER_PORT']). (Pierre)
 
+- cURL:
+  . Fixed bug #60439 (curl_copy_handle segfault when used with
+    CURLOPT_PROGRESSFUNCTION). (Pierrick)
+
 - Intl:
   . Added support for UTS #46. (Gustavo)
 
index 52c4314f1c9b86c2011d894b8a6708c21a4e292e..d1ddcfe9e6bb50a867311ecc95ca5f3f44d728be 100644 (file)
@@ -1645,11 +1645,18 @@ PHP_FUNCTION(curl_copy_handle)
                zval_add_ref(&ch->handlers->write_header->func_name);
                dupch->handlers->write_header->func_name = ch->handlers->write_header->func_name;
        }
+       
+       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_ERRORBUFFER,       dupch->err.str);
        curl_easy_setopt(dupch->cp, CURLOPT_FILE,              (void *) dupch);
        curl_easy_setopt(dupch->cp, CURLOPT_INFILE,            (void *) dupch);
        curl_easy_setopt(dupch->cp, CURLOPT_WRITEHEADER,       (void *) dupch);
+       curl_easy_setopt(dupch->cp, CURLOPT_PROGRESSDATA,      (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!