xref: /PHP-5.4/ext/curl/tests/bug54798.phpt (revision 1260d8e1)
1--TEST--
2Bug #54798 (Segfault when CURLOPT_STDERR file pointer is closed before calling curl_exec)
3--SKIPIF--
4<?php
5if (!extension_loaded("curl")) {
6	exit("skip curl extension not loaded");
7}
8if (false === getenv('PHP_CURL_HTTP_REMOTE_SERVER'))  {
9	exit("skip PHP_CURL_HTTP_REMOTE_SERVER env variable is not defined");
10}
11?>
12--FILE--
13<?php
14
15function checkForClosedFilePointer($host, $curl_option, $description) {
16	$fp = fopen(dirname(__FILE__) . '/bug54798.tmp', 'w+');
17
18	$ch = curl_init();
19
20	// we also need CURLOPT_VERBOSE to be set to test CURLOPT_STDERR properly
21	if (CURLOPT_STDERR == $curl_option) {
22		curl_setopt($ch, CURLOPT_VERBOSE, 1);
23	}
24
25    if (CURLOPT_INFILE == $curl_option) {
26        curl_setopt($ch, CURLOPT_UPLOAD, 1);
27    }
28
29	curl_setopt($ch, $curl_option, $fp);
30
31	curl_setopt($ch, CURLOPT_URL, $host);
32	curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
33
34	fclose($fp); // <-- premature close of $fp caused a crash!
35
36	curl_exec($ch);
37
38	curl_close($ch);
39
40	echo "Ok for $description\n";
41}
42
43$options_to_check = array(
44	"CURLOPT_STDERR",
45    "CURLOPT_WRITEHEADER",
46    "CURLOPT_FILE",
47    "CURLOPT_INFILE"
48);
49
50$host = getenv('PHP_CURL_HTTP_REMOTE_SERVER');
51foreach($options_to_check as $option) {
52	checkForClosedFilePointer($host, constant($option), $option);
53}
54
55?>
56--CLEAN--
57<?php @unlink(dirname(__FILE__) . '/bug54798.tmp'); ?>
58--EXPECTF--
59Warning: curl_exec(): CURLOPT_STDERR resource has gone away, resetting to stderr in %sbug54798.php on line %d
60* About to connect() %a
61* Closing connection #%d
62Ok for CURLOPT_STDERR
63
64Warning: curl_exec(): CURLOPT_WRITEHEADER resource has gone away, resetting to default in %sbug54798.php on line 24
65Ok for CURLOPT_WRITEHEADER
66
67Warning: curl_exec(): CURLOPT_FILE resource has gone away, resetting to default in %sbug54798.php on line 24
68%a
69Ok for CURLOPT_FILE
70
71Warning: curl_exec(): CURLOPT_INFILE resource has gone away, resetting to default in %sbug54798.php on line %d
72Ok for CURLOPT_INFILE
73