xref: /PHP-5.6/ext/curl/tests/bug48203_multi.phpt (revision c507c9f0)
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--SKIPIF--
4<?php
5include 'skipif.inc';
6?>
7--FILE--
8<?php
9include 'server.inc';
10function checkForClosedFilePointer($curl_option, $description) {
11	$fp = fopen(dirname(__FILE__) . '/bug48203.tmp', 'w');
12
13	$ch1 = curl_init();
14	$ch2 = curl_init();
15
16	$options = array(
17		CURLOPT_RETURNTRANSFER => 1,
18		$curl_option => $fp,
19		CURLOPT_URL => curl_cli_server_start()
20	);
21
22	// we also need to set CURLOPT_VERBOSE to test CURLOPT_STDERR properly
23	if (CURLOPT_STDERR == $curl_option) {
24		$options[CURLOPT_VERBOSE] = 1;
25	}
26
27	if (CURLOPT_INFILE == $curl_option) {
28	    $options[CURLOPT_UPLOAD] = 1;
29	}
30
31	curl_setopt_array($ch1, $options);
32	curl_setopt_array($ch2, $options);
33
34	fclose($fp); // <-- premature close of $fp caused a crash!
35
36	$mh = curl_multi_init();
37
38	curl_multi_add_handle($mh, $ch1);
39	curl_multi_add_handle($mh, $ch2);
40
41	$active = 0;
42	do {
43		curl_multi_exec($mh, $active);
44	} while ($active > 0);
45
46	curl_multi_remove_handle($mh, $ch1);
47	curl_multi_remove_handle($mh, $ch2);
48	curl_multi_close($mh);
49
50	echo "Ok for $description\n";
51}
52
53$options_to_check = array(
54	"CURLOPT_STDERR", "CURLOPT_WRITEHEADER", "CURLOPT_FILE", "CURLOPT_INFILE"
55);
56
57foreach($options_to_check as $option) {
58	checkForClosedFilePointer(constant($option), $option);
59}
60
61?>
62--CLEAN--
63<?php @unlink(dirname(__FILE__) . '/bug48203.tmp'); ?>
64--EXPECTF--
65Warning: curl_multi_exec(): CURLOPT_STDERR resource has gone away, resetting to stderr in %sbug48203_multi.php on line 36
66
67Warning: curl_multi_exec(): CURLOPT_STDERR resource has gone away, resetting to stderr in %sbug48203_multi.php on line 36
68%A
69Ok for CURLOPT_STDERR
70%A
71Warning: curl_multi_exec(): CURLOPT_WRITEHEADER resource has gone away, resetting to default in %sbug48203_multi.php on line 36
72
73Warning: curl_multi_exec(): CURLOPT_WRITEHEADER resource has gone away, resetting to default in %sbug48203_multi.php on line 36
74Ok for CURLOPT_WRITEHEADER
75
76Warning: curl_multi_exec(): CURLOPT_FILE resource has gone away, resetting to default in %sbug48203_multi.php on line 36
77
78Warning: curl_multi_exec(): CURLOPT_FILE resource has gone away, resetting to default in %sbug48203_multi.php on line 36
79%AOk for CURLOPT_FILE
80
81Warning: curl_multi_exec(): CURLOPT_INFILE resource has gone away, resetting to default in %sbug48203_multi.php on line 36
82
83Warning: curl_multi_exec(): CURLOPT_INFILE resource has gone away, resetting to default in %sbug48203_multi.php on line 36
84Ok for CURLOPT_INFILE
85