Reopened bug and uploaded my patch here: http://bugs.php.net/bug.php?id=48203.

2011/6/9 Shein Alexey <sh...@php.net>:
> shein                                    Thu, 09 Jun 2011 07:16:13 +0000
>
> Revision: http://svn.php.net/viewvc?view=revision&revision=311959
>
> Log:
> Updated (currently failing) test for bug48203 with curl_stderr and added also 
> curl_multi_exec variant of this test.
>
> Bug: http://bugs.php.net/48203 (Closed) crash when CURLOPT_STDERR is set to 
> regular file
>
> Changed paths:
>    U   php/php-src/trunk/ext/curl/tests/bug48203.phpt
>    A + php/php-src/trunk/ext/curl/tests/bug48203_multi.phpt
>        (from php/php-src/trunk/ext/curl/tests/bug48203.phpt:r311171)
>    A   
> php/php-src/trunk/ext/curl/tests/curl_file_deleted_before_curl_close.phpt
>
> Modified: php/php-src/trunk/ext/curl/tests/bug48203.phpt
> ===================================================================
> --- php/php-src/trunk/ext/curl/tests/bug48203.phpt      2011-06-09 06:49:31 
> UTC (rev 311958)
> +++ php/php-src/trunk/ext/curl/tests/bug48203.phpt      2011-06-09 07:16:13 
> UTC (rev 311959)
> @@ -1,5 +1,5 @@
>  --TEST--
> -Bug #48203 (Crash when CURLOPT_STDERR is set to regular file)
> +Bug #48203 (Crash when file pointers passed to curl are closed before 
> calling curl_exec)
>  --SKIPIF--
>  <?php
>  if (!extension_loaded("curl")) {
> @@ -12,22 +12,68 @@
>  --FILE--
>  <?php
>
> -$fp = fopen(dirname(__FILE__) . '/bug48203.tmp', 'w');
> +function checkForClosedFilePointer($curl_option, $description) {
> +       $fp = fopen(dirname(__FILE__) . '/bug48203.tmp', 'w+');
>
> -$ch = curl_init();
> +       $ch = curl_init();
>
> -curl_setopt($ch, CURLOPT_VERBOSE, 1);
> -curl_setopt($ch, CURLOPT_STDERR, $fp);
> -curl_setopt($ch, CURLOPT_URL, "");
> +       // we also need CURLOPT_VERBOSE to be set to test CURLOPT_STDERR 
> properly
> +       if (CURLOPT_STDERR == $curl_option) {
> +               curl_setopt($ch, CURLOPT_VERBOSE, 1);
> +       }
>
> -fclose($fp); // <-- premature close of $fp caused a crash!
> +    if (CURLOPT_INFILE == $curl_option) {
> +        curl_setopt($ch, CURLOPT_UPLOAD, 1);
> +    }
>
> -curl_exec($ch);
> +       curl_setopt($ch, $curl_option, $fp);
> +
> +       curl_setopt($ch, CURLOPT_URL, 'localhost');
> +       curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
>
> -echo "Ok\n";
> +       fclose($fp); // <-- premature close of $fp caused a crash!
>
> +       curl_exec($ch);
> +
> +       curl_close($ch);
> +
> +       echo "Ok for $description\n";
> +}
> +
> +$options_to_check = array(
> +       "CURLOPT_STDERR",
> +    "CURLOPT_WRITEHEADER",
> +    "CURLOPT_FILE",
> +    "CURLOPT_INFILE"
> +);
> +
> +foreach($options_to_check as $option) {
> +       checkForClosedFilePointer(constant($option), $option);
> +}
> +
>  ?>
>  --CLEAN--
>  <?php @unlink(dirname(__FILE__) . '/bug48203.tmp'); ?>
> ---EXPECT--
> -Ok
> +--EXPECTF--
> +Warning: curl_exec(): %d is not a valid stream resource in %s on line %d
> +
> +Warning: curl_exec(): CURLOPT_STDERR handle is incorrect in %s on line %d
> +* About to connect() %a
> +* Closing connection #%d
> +Ok for CURLOPT_STDERR
> +
> +Warning: curl_exec(): %d is not a valid stream resource in %s on line %d
> +
> +Warning: curl_exec(): CURLOPT_WRITEHEADER handle is incorrect in %s on line 
> %d
> +Ok for CURLOPT_WRITEHEADER
> +
> +Warning: curl_exec(): %d is not a valid stream resource in %s on line %d
> +
> +Warning: curl_exec(): CURLOPT_FILE handle is incorrect in %s on line %d
> +%a
> +Ok for CURLOPT_FILE
> +
> +Warning: curl_exec(): %d is not a valid stream resource in %s on line %d
> +
> +Warning: curl_exec(): CURLOPT_INFILE handle is incorrect in %s on line %d
> +Ok for CURLOPT_INFILE
>
> Copied: php/php-src/trunk/ext/curl/tests/bug48203_multi.phpt (from rev 
> 311171, php/php-src/trunk/ext/curl/tests/bug48203.phpt)
> ===================================================================
> --- php/php-src/trunk/ext/curl/tests/bug48203_multi.phpt                      
>           (rev 0)
> +++ php/php-src/trunk/ext/curl/tests/bug48203_multi.phpt        2011-06-09 
> 07:16:13 UTC (rev 311959)
> @@ -0,0 +1,106 @@
> +--TEST--
> +Variation of bug #48203 with curl_multi_exec (Crash when file pointers 
> passed to curl are closed before calling curl_multi_exec)
> +--SKIPIF--
> +<?php
> +if (!extension_loaded("curl")) {
> +       exit("skip curl extension not loaded");
> +}
> +if (false === getenv('PHP_CURL_HTTP_REMOTE_SERVER'))  {
> +       exit("skip PHP_CURL_HTTP_REMOTE_SERVER env variable is not defined");
> +}
> +?>
> +--FILE--
> +<?php
> +
> +function checkForClosedFilePointer($curl_option, $description) {
> +       $fp = fopen(dirname(__FILE__) . '/bug48203.tmp', 'w');
> +
> +       $ch1 = curl_init();
> +       $ch2 = curl_init();
> +
> +       $options = array(
> +               CURLOPT_RETURNTRANSFER => 1,
> +               $curl_option => $fp,
> +               CURLOPT_URL => getenv("PHP_CURL_HTTP_REMOTE_SERVER")
> +       );
> +
> +       // we also need to set CURLOPT_VERBOSE to test CURLOPT_STDERR properly
> +       if (CURLOPT_STDERR == $curl_option) {
> +               $options[CURLOPT_VERBOSE] = 1;
> +       }
> +
> +       if (CURLOPT_INFILE == $curl_option) {
> +           $options[CURLOPT_UPLOAD] = 1;
> +       }
> +
> +       curl_setopt_array($ch1, $options);
> +       curl_setopt_array($ch2, $options);
> +
> +       fclose($fp); // <-- premature close of $fp caused a crash!
> +
> +       $mh = curl_multi_init();
> +
> +       curl_multi_add_handle($mh, $ch1);
> +       curl_multi_add_handle($mh, $ch2);
> +
> +       $active = 0;
> +       do {
> +               curl_multi_exec($mh, $active);
> +       } while ($active > 0);
> +
> +       curl_multi_remove_handle($mh, $ch1);
> +       curl_multi_remove_handle($mh, $ch2);
> +       curl_multi_close($mh);
> +
> +       echo "Ok for $description\n";
> +}
> +
> +$options_to_check = array(
> +       "CURLOPT_STDERR", "CURLOPT_WRITEHEADER", "CURLOPT_FILE", 
> "CURLOPT_INFILE"
> +);
> +
> +foreach($options_to_check as $option) {
> +       checkForClosedFilePointer(constant($option), $option);
> +}
> +
> +?>
> +--CLEAN--
> +<?php @unlink(dirname(__FILE__) . '/bug48203.tmp'); ?>
> +--EXPECTF--
> +Warning: curl_multi_exec(): %d is not a valid stream resource in %s on line 
> %d
> +
> +Warning: curl_multi_exec(): CURLOPT_STDERR handle is incorrect in %s on line 
> %d
> +
> +Warning: curl_multi_exec(): %d is not a valid stream resource in %s on line 
> %d
> +
> +Warning: curl_multi_exec(): CURLOPT_STDERR handle is incorrect in %s on line 
> %d
> +%a
> +Ok for CURLOPT_STDERR
> +
> +Warning: curl_multi_exec(): %d is not a valid stream resource in %s on line 
> %d
> +
> +Warning: curl_multi_exec(): CURLOPT_WRITEHEADER handle is incorrect in %s on 
> line %d
> +
> +Warning: curl_multi_exec(): %d is not a valid stream resource in %s on line 
> %d
> +
> +Warning: curl_multi_exec(): CURLOPT_WRITEHEADER handle is incorrect in %s on 
> line %d
> +%AOk for CURLOPT_WRITEHEADER
> +
> +Warning: curl_multi_exec(): %d is not a valid stream resource in %s on line 
> %d
> +
> +Warning: curl_multi_exec(): CURLOPT_FILE handle is incorrect in %s on line %d
> +
> +Warning: curl_multi_exec(): %d is not a valid stream resource in %s on line 
> %d
> +
> +Warning: curl_multi_exec(): CURLOPT_FILE handle is incorrect in %s on line %d
> +%a
> +Ok for CURLOPT_FILE
> +
> +Warning: curl_multi_exec(): %d is not a valid stream resource in %s on line 
> %d
> +
> +Warning: curl_multi_exec(): CURLOPT_INFILE handle is incorrect in %s on line 
> %d
> +
> +Warning: curl_multi_exec(): %d is not a valid stream resource in %s on line 
> %d
> +
> +Warning: curl_multi_exec(): CURLOPT_INFILE handle is incorrect in %s on line 
> %d
> +Ok for CURLOPT_INFILE
>
>
> Property changes on: php/php-src/trunk/ext/curl/tests/bug48203_multi.phpt
> ___________________________________________________________________
> Added: cvs2svn:cvs-rev
>   + 1.1.2.3
> Added: svn:keywords
>   + Id Rev Revision Date LastChangedDate LastChangedRevision Author 
> LastChangedBy HeadURL URL
> Added: svn:eol-style
>   + native
>
> Added: 
> php/php-src/trunk/ext/curl/tests/curl_file_deleted_before_curl_close.phpt
> ===================================================================
> --- php/php-src/trunk/ext/curl/tests/curl_file_deleted_before_curl_close.phpt 
>                           (rev 0)
> +++ php/php-src/trunk/ext/curl/tests/curl_file_deleted_before_curl_close.phpt 
>   2011-06-09 07:16:13 UTC (rev 311959)
> @@ -0,0 +1,37 @@
> +--TEST--
> +Memory corruption error if fp of just created file is closed before 
> curl_close.
> +--CREDITS--
> +Alexey Shein <con...@gmail.com>
> +--SKIPIF--
> +<?php if (!extension_loaded("curl") || false === 
> getenv('PHP_CURL_HTTP_REMOTE_SERVER')) print "skip"; ?>
> +--FILE--
> +<?php
> +
> +$ch = curl_init(getenv('PHP_CURL_HTTP_REMOTE_SERVER'));
> +
> +$temp_file = dirname(__FILE__) . '/curl_file_deleted_before_curl_close.tmp';
> +if (file_exists($temp_file)) {
> +       unlink($temp_file); // file should not exist before test
> +}
> +
> +$handle = fopen($temp_file, 'w');
> +
> +curl_setopt($ch, CURLOPT_STDERR, $handle);
> +curl_setopt($ch, CURLOPT_VERBOSE, 1);
> +curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
> +
> +curl_exec($ch);
> +
> +fclose($handle); // causes glibc memory error
> +
> +//unlink($temp_file); // uncomment to test segfault (file not found on 
> iowrite.c)
> +
> +curl_close($ch);
> +echo "Closed correctly\n";
> +?>
> +--CLEAN--
> +<?php
> +unlink(dirname(__FILE__) . '/curl_file_deleted_before_curl_close.tmp');
> +?>
> +--EXPECTF--
> +Closed correctly
>
>
> --
> PHP CVS Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>



-- 
Regards,
Shein Alexey

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

Reply via email to