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