]> 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).

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

diff --git a/NEWS b/NEWS
index 389f26c055f2163e13330ad13002d67d9cfb52e1..e89b7b0a07b6db7a3b4a9429739ef4dc2dc81df2 100644 (file)
--- a/NEWS
+++ b/NEWS
   mssql_connect). (Felipe)
 - Fixed bug #52827 (cURL leaks handle and causes assertion error
   (CURLOPT_STDERR)). (Gustavo)
+- Fixed bug #52820 (writes to fopencookie FILE* not commited when seeking the
+  stream). (Gustavo)
 - Fixed bug #52786 (PHP should reset section to [PHP] after ini sections).
   (Fedora at famillecollet dot com)
 - Fixed bug #52784 (Race condition when handling many concurrent signals).
diff --git a/ext/standard/tests/file/bug52820.phpt b/ext/standard/tests/file/bug52820.phpt
new file mode 100644 (file)
index 0000000..70ac9e0
--- /dev/null
@@ -0,0 +1,98 @@
+--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 "\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
+Done.\r
+--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 "\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
+Done.\r
index 023977d39eddea6d57ddd76741c7ec69a31dfe1a..e08c5e122ce2feca657142ae295cdf0aa00205fd 100755 (executable)
@@ -1093,6 +1093,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) {