1--TEST-- 2Variation of bug #48203 with curl_multi_exec (Crash when file pointers passed to curl are closed before calling curl_multi_exec) 3--EXTENSIONS-- 4curl 5--FILE-- 6<?php 7include 'server.inc'; 8function checkForClosedFilePointer($target_url, $curl_option, $description) { 9 $fp = fopen(__DIR__ . '/bug48203.tmp', 'w'); 10 11 $ch1 = curl_init(); 12 $ch2 = curl_init(); 13 14 $options = array( 15 CURLOPT_RETURNTRANSFER => 1, 16 $curl_option => $fp, 17 CURLOPT_URL => $target_url, 18 ); 19 20 // we also need to set CURLOPT_VERBOSE to test CURLOPT_STDERR properly 21 if (CURLOPT_STDERR == $curl_option) { 22 $options[CURLOPT_VERBOSE] = 1; 23 } 24 25 if (CURLOPT_INFILE == $curl_option) { 26 $options[CURLOPT_UPLOAD] = 1; 27 } 28 29 curl_setopt_array($ch1, $options); 30 curl_setopt_array($ch2, $options); 31 32 fclose($fp); // <-- premature close of $fp caused a crash! 33 34 $mh = curl_multi_init(); 35 36 curl_multi_add_handle($mh, $ch1); 37 curl_multi_add_handle($mh, $ch2); 38 39 $active = 0; 40 do { 41 curl_multi_exec($mh, $active); 42 } while ($active > 0); 43 44 curl_multi_remove_handle($mh, $ch1); 45 curl_multi_remove_handle($mh, $ch2); 46 curl_multi_close($mh); 47 48 // Force curl to output results 49 fflush(STDERR); 50 fflush(STDOUT); 51 52 echo "Ok for $description\n"; 53} 54 55$options_to_check = array( 56 "CURLOPT_STDERR", "CURLOPT_WRITEHEADER", "CURLOPT_FILE", "CURLOPT_INFILE" 57); 58 59$target_url = curl_cli_server_start(); 60foreach($options_to_check as $option) { 61 checkForClosedFilePointer($target_url, constant($option), $option); 62} 63 64?> 65--CLEAN-- 66<?php @unlink(__DIR__ . '/bug48203.tmp'); ?> 67--EXPECTF-- 68Warning: curl_multi_add_handle(): CURLOPT_STDERR resource has gone away, resetting to stderr in %s on line %d 69%A 70Warning: curl_multi_add_handle(): CURLOPT_STDERR resource has gone away, resetting to stderr in %s on line %d 71%A 72Ok for CURLOPT_STDERR 73 74Warning: curl_multi_add_handle(): CURLOPT_WRITEHEADER resource has gone away, resetting to default in %s on line %d 75 76Warning: curl_multi_add_handle(): CURLOPT_WRITEHEADER resource has gone away, resetting to default in %s on line %d 77Ok for CURLOPT_WRITEHEADER 78 79Warning: curl_multi_add_handle(): CURLOPT_FILE resource has gone away, resetting to default in %s on line %d 80 81Warning: curl_multi_add_handle(): CURLOPT_FILE resource has gone away, resetting to default in %s on line %d 82%AOk for CURLOPT_FILE 83 84Warning: curl_multi_add_handle(): CURLOPT_INFILE resource has gone away, resetting to default in %s on line %d 85 86Warning: curl_multi_add_handle(): CURLOPT_INFILE resource has gone away, resetting to default in %s on line %d 87Ok for CURLOPT_INFILE 88