xref: /PHP-8.0/ext/standard/tests/file/bug52820.phpt (revision 7aacc705)
1--TEST--
2Bug #52820 (writes to fopencookie FILE* not committed when seeking the stream)
3--SKIPIF--
4<?php
5if (!function_exists('zend_leak_variable'))
6   die("skip only for debug builds");
7/* unfortunately no standard function does a cast to FILE*, so we need
8 * curl to test this */
9if (!extension_loaded("curl")) exit("skip curl extension not loaded");
10$handle=curl_init('file:///i_dont_exist/');
11curl_setopt($handle, CURLOPT_VERBOSE, true);
12curl_setopt($handle, CURLOPT_RETURNTRANSFER, true);
13if (!@curl_setopt($handle, CURLOPT_STDERR, fopen("php://memory", "w+")))
14    die("skip fopencookie not supported on this platform");
15--FILE--
16<?php
17function do_stuff($url) {
18    $handle=curl_init('file:///i_dont_exist/');
19    curl_setopt($handle, CURLOPT_VERBOSE, true);
20    curl_setopt($handle, CURLOPT_RETURNTRANSFER, true);
21    curl_setopt($handle, CURLOPT_STDERR, $o = fopen($url, "w+"));
22    curl_exec($handle);
23    echo "About to rewind!\n";
24    rewind($o);
25    echo stream_get_contents($o);
26    return $o;
27}
28
29echo "temp stream (close after):\n";
30fclose(do_stuff("php://temp"));
31
32echo "\nmemory stream (close after):\n";
33fclose(do_stuff("php://memory"));
34
35echo "\ntemp stream (leak):\n";
36zend_leak_variable(do_stuff("php://temp"));
37
38echo "\nmemory stream (leak):\n";
39zend_leak_variable(do_stuff("php://memory"));
40
41echo "\nDone.\n";
42?>
43--EXPECTF--
44temp stream (close after):
45About to rewind!
46* Couldn't open file /i_dont_exist/
47* Closing connection%A%d
48
49memory stream (close after):
50About to rewind!
51* Couldn't open file /i_dont_exist/
52* Closing connection%A%d
53
54temp stream (leak):
55About to rewind!
56* Couldn't open file /i_dont_exist/
57* Closing connection%A%d
58
59memory stream (leak):
60About to rewind!
61* Couldn't open file /i_dont_exist/
62* Closing connection%A%d
63
64Done.
65