Commit:    9cf0139460c7531ebe8fdd523ba6cf7067a7f282
Author:    Pierrick Charron <pierr...@php.net>         Thu, 16 Aug 2012 
14:48:44 -0400
Parents:   8649e4236b12ce9b90356a5804be96bd1f67bcd6
Branches:  PHP-5.3 PHP-5.4 master

Link:       
http://git.php.net/?p=php-src.git;a=commitdiff;h=9cf0139460c7531ebe8fdd523ba6cf7067a7f282

Log:
Fixed bug #62839

curl_copy_handle segfault with CURLOPT_FILE. The refcount was incremented
before the assignement.

Bugs:
https://bugs.php.net/62839

Changed paths:
  M  NEWS
  M  ext/curl/interface.c
  A  ext/curl/tests/bug62839.phpt


Diff:
diff --git a/NEWS b/NEWS
index 8da7256..7f5c48b 100644
--- 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.hampartsum...@gmail.com, Laruence)
 
diff --git a/ext/curl/interface.c b/ext/curl/interface.c
index 94be60f..7b72873 100644
--- a/ext/curl/interface.c
+++ b/ext/curl/interface.c
@@ -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
index 0000000..39e6fc9
--- /dev/null
+++ b/ext/curl/tests/bug62839.phpt
@@ -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!


--
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to