]> granicus.if.org Git - php/commitdiff
Fixed bug #62839
authorPierrick Charron <pierrick@php.net>
Thu, 16 Aug 2012 18:48:44 +0000 (14:48 -0400)
committerPierrick Charron <pierrick@php.net>
Thu, 16 Aug 2012 18:48:44 +0000 (14:48 -0400)
curl_copy_handle segfault with CURLOPT_FILE. The refcount was incremented
before the assignement.

NEWS
ext/curl/interface.c
ext/curl/tests/bug62839.phpt [new file with mode: 0644]

diff --git a/NEWS b/NEWS
index 8da7256017347625c514cd81828a3e55760cd7b1..7f5c48b2aae933c897ae47ba459cb423a64916ca 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -13,6 +13,7 @@ PHP                                                                        NEWS
     with run-test.php). (Laruence)
 
 - CURL:
+  . Fixed bug #62839 (curl_copy_handle segfault with CURLOPT_FILE). (Pierrick)
   . Fixed bug #62499 (curl_setopt($ch, CURLOPT_COOKIEFILE, "") returns false).
     (r.hampartsumyan@gmail.com, Laruence)
 
index 94be60fd5d5a78e19ecafdc92b191752ef502b10..7b72873038281e3f56b68d140d68ba9e297f62ab 100644 (file)
@@ -1610,9 +1610,9 @@ PHP_FUNCTION(curl_copy_handle)
        dupch->uses = 0;
        ch->uses++;
        if (ch->handlers->write->stream) {
-               Z_ADDREF_P(dupch->handlers->write->stream);
-               dupch->handlers->write->stream = ch->handlers->write->stream;
+               Z_ADDREF_P(ch->handlers->write->stream);
        }
+       dupch->handlers->write->stream = ch->handlers->write->stream;
        dupch->handlers->write->method = ch->handlers->write->method;
        dupch->handlers->write->type   = ch->handlers->write->type;
        if (ch->handlers->read->stream) {
diff --git a/ext/curl/tests/bug62839.phpt b/ext/curl/tests/bug62839.phpt
new file mode 100644 (file)
index 0000000..39e6fc9
--- /dev/null
@@ -0,0 +1,18 @@
+--TEST--
+Bug #62839 (curl_copy_handle segfault with CURLOPT_FILE)
+--SKIPIF--
+<?php if (!extension_loaded("curl")) print "skip"; 
+?>
+--FILE--
+<?php
+$curl = curl_init();
+
+$fd = fopen('/tmp/test', 'wb');
+curl_setopt($curl, CURLOPT_FILE, $fd);
+
+curl_copy_handle($curl);
+
+echo 'DONE!';
+?>
+--EXPECTF--
+DONE!