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