1--TEST-- 2Bug #54798 (Segfault when CURLOPT_STDERR file pointer is closed before calling curl_exec) 3--SKIPIF-- 4<?php 5include 'skipif.inc'; 6if(substr(PHP_OS, 0, 3) == 'WIN' ) { 7 die('skip not for Windows'); 8} 9?> 10--FILE-- 11<?php 12 13function checkForClosedFilePointer($host, $curl_option, $description) { 14 $fp = fopen(dirname(__FILE__) . '/bug54798.tmp', 'w+'); 15 16 $ch = curl_init(); 17 18 // we also need CURLOPT_VERBOSE to be set to test CURLOPT_STDERR properly 19 if (CURLOPT_STDERR == $curl_option) { 20 curl_setopt($ch, CURLOPT_VERBOSE, 1); 21 } 22 23 if (CURLOPT_INFILE == $curl_option) { 24 curl_setopt($ch, CURLOPT_UPLOAD, 1); 25 } 26 27 curl_setopt($ch, $curl_option, $fp); 28 29 curl_setopt($ch, CURLOPT_URL, $host); 30 curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 31 32 fclose($fp); // <-- premature close of $fp caused a crash! 33 34 curl_exec($ch); 35 36 curl_close($ch); 37 38 echo "Ok for $description\n"; 39} 40 41$options_to_check = array( 42 "CURLOPT_STDERR", 43 "CURLOPT_WRITEHEADER", 44 "CURLOPT_FILE", 45 "CURLOPT_INFILE" 46); 47 48include 'server.inc'; 49$host = curl_cli_server_start(); 50foreach($options_to_check as $option) { 51 checkForClosedFilePointer($host, constant($option), $option); 52} 53 54?> 55===DONE=== 56--CLEAN-- 57<?php @unlink(dirname(__FILE__) . '/bug54798.tmp'); ?> 58--EXPECTF-- 59%a 60%aOk for CURLOPT_STDERR 61%aOk for CURLOPT_WRITEHEADER 62%aOk for CURLOPT_FILE 63%aOk for CURLOPT_INFILE 64===DONE=== 65