]> granicus.if.org Git - php/commitdiff
- Fixed bug #52820 (writes to fopencookie FILE* not commited when seeking the
authorGustavo André dos Santos Lopes <cataphract@php.net>
Mon, 15 Nov 2010 18:22:52 +0000 (18:22 +0000)
committerGustavo André dos Santos Lopes <cataphract@php.net>
Mon, 15 Nov 2010 18:22:52 +0000 (18:22 +0000)
  stream).

ext/standard/tests/file/bug52820.phpt [new file with mode: 0644]
main/streams/streams.c

diff --git a/ext/standard/tests/file/bug52820.phpt b/ext/standard/tests/file/bug52820.phpt
new file mode 100644 (file)
index 0000000..a631bef
--- /dev/null
@@ -0,0 +1,69 @@
+--TEST--\r
+Bug #52820 (writes to fopencookie FILE* not commited when seeking the stream)\r
+--SKIPIF--\r
+<?php\r
+/* unfortunately no standard function does a cast to FILE*, so we need\r
+ * curl to test this */\r
+if (!extension_loaded("curl")) exit("skip curl extension not loaded");\r
+$handle=curl_init('http://127.0.0.1:37349/');\r
+curl_setopt($handle, CURLOPT_VERBOSE, true);\r
+curl_setopt($handle, CURLOPT_RETURNTRANSFER, true);\r
+if (!curl_setopt($handle, CURLOPT_STDERR, fopen("php://memory", "w+")))\r
+    die("skip fopencookie not supported on this platform");\r
+--FILE--\r
+<?php\r
+function do_stuff($url) {\r
+    $handle=curl_init('http://127.0.0.1:37349/');\r
+    curl_setopt($handle, CURLOPT_VERBOSE, true);\r
+    curl_setopt($handle, CURLOPT_RETURNTRANSFER, true);\r
+    curl_setopt($handle, CURLOPT_STDERR, $o = fopen($url, "w+"));\r
+    curl_exec($handle);\r
+    echo "About to rewind!\n";\r
+    rewind($o);\r
+    echo stream_get_contents($o);\r
+    return $o;\r
+}\r
+\r
+echo "temp stream (close after):\n";\r
+fclose(do_stuff("php://temp"));\r
+\r
+echo "\nmemory stream (close after):\n";\r
+fclose(do_stuff("php://memory"));\r
+\r
+echo "\ntemp stream (leak):\n";\r
+leak_variable(do_stuff("php://temp"), true);\r
+\r
+echo "\nmemory stream (leak):\n";\r
+leak_variable(do_stuff("php://memory"), true);\r
+\r
+echo "\nDone.\n";\r
+--EXPECT--\r
+temp stream (close after):\r
+About to rewind!\r
+* About to connect() to 127.0.0.1 port 37349 (#0)\r
+*   Trying 127.0.0.1... * Connection refused\r
+* couldn't connect to host\r
+* Closing connection #0\r
+\r
+memory stream (close after):\r
+About to rewind!\r
+* About to connect() to 127.0.0.1 port 37349 (#0)\r
+*   Trying 127.0.0.1... * Connection refused\r
+* couldn't connect to host\r
+* Closing connection #0\r
+\r
+temp stream (leak):\r
+About to rewind!\r
+* About to connect() to 127.0.0.1 port 37349 (#0)\r
+*   Trying 127.0.0.1... * Connection refused\r
+* couldn't connect to host\r
+* Closing connection #0\r
+\r
+memory stream (leak):\r
+About to rewind!\r
+* About to connect() to 127.0.0.1 port 37349 (#0)\r
+*   Trying 127.0.0.1... * Connection refused\r
+* couldn't connect to host\r
+* Closing connection #0\r
+\r
+Done.\r
index b3f40422c30ef83e91b5bb3b9429920362d3740a..33a737bbfa437711ff16a24e96d52dceb15acfb1 100755 (executable)
@@ -1164,6 +1164,11 @@ PHPAPI off_t _php_stream_tell(php_stream *stream TSRMLS_DC)
 
 PHPAPI int _php_stream_seek(php_stream *stream, off_t offset, int whence TSRMLS_DC)
 {
+       if (stream->fclose_stdiocast == PHP_STREAM_FCLOSE_FOPENCOOKIE) {
+               /* flush to commit data written to the fopencookie FILE* */
+               fflush(stream->stdiocast);
+       }
+
        /* handle the case where we are in the buffer */
        if ((stream->flags & PHP_STREAM_FLAG_NO_BUFFER) == 0) {
                switch(whence) {