diff options
author | Gustavo André dos Santos Lopes <cataphract@php.net> | 2010-11-15 18:22:52 +0000 |
---|---|---|
committer | Gustavo André dos Santos Lopes <cataphract@php.net> | 2010-11-15 18:22:52 +0000 |
commit | 1045aa2a7c8497ff9f74a1078f44e675c558094a (patch) | |
tree | 94e156800f39e6fc2473db05da858f9d4b553648 | |
parent | d91c4be0d6ac5c52f6a09254103b154d38852ed2 (diff) | |
download | php-git-1045aa2a7c8497ff9f74a1078f44e675c558094a.tar.gz |
- Fixed bug #52820 (writes to fopencookie FILE* not commited when seeking the
stream).
-rw-r--r-- | NEWS | 2 | ||||
-rw-r--r-- | ext/standard/tests/file/bug52820.phpt | 98 | ||||
-rwxr-xr-x | main/streams/streams.c | 5 |
3 files changed, 105 insertions, 0 deletions
@@ -122,6 +122,8 @@ 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 index 0000000000..70ac9e02b9 --- /dev/null +++ b/ext/standard/tests/file/bug52820.phpt @@ -0,0 +1,98 @@ +--TEST--
+Bug #52820 (writes to fopencookie FILE* not commited when seeking the stream)
+--SKIPIF--
+<?php
+/* unfortunately no standard function does a cast to FILE*, so we need
+ * curl to test this */
+if (!extension_loaded("curl")) exit("skip curl extension not loaded");
+$handle=curl_init('http://127.0.0.1:37349/');
+curl_setopt($handle, CURLOPT_VERBOSE, true);
+curl_setopt($handle, CURLOPT_RETURNTRANSFER, true);
+if (!curl_setopt($handle, CURLOPT_STDERR, fopen("php://memory", "w+")))
+ die("skip fopencookie not supported on this platform");
+--FILE--
+<?php
+function do_stuff($url) {
+ $handle=curl_init('http://127.0.0.1:37349/');
+ curl_setopt($handle, CURLOPT_VERBOSE, true);
+ curl_setopt($handle, CURLOPT_RETURNTRANSFER, true);
+ curl_setopt($handle, CURLOPT_STDERR, $o = fopen($url, "w+"));
+ curl_exec($handle);
+ echo "About to rewind!\n";
+ rewind($o);
+ echo stream_get_contents($o);
+ return $o;
+}
+
+echo "temp stream (close after):\n";
+fclose(do_stuff("php://temp"));
+
+echo "\nmemory stream (close after):\n";
+fclose(do_stuff("php://memory"));
+
+echo "\nDone.\n";
+--EXPECT--
+temp stream (close after):
+About to rewind!
+* About to connect() to 127.0.0.1 port 37349 (#0)
+* Trying 127.0.0.1... * Connection refused
+* couldn't connect to host
+* Closing connection #0
+
+memory stream (close after):
+About to rewind!
+* About to connect() to 127.0.0.1 port 37349 (#0)
+* Trying 127.0.0.1... * Connection refused
+* couldn't connect to host
+* Closing connection #0
+
+Done.
+--TEST--
+Bug #52820 (writes to fopencookie FILE* not commited when seeking the stream)
+--SKIPIF--
+<?php
+/* unfortunately no standard function does a cast to FILE*, so we need
+ * curl to test this */
+if (!extension_loaded("curl")) exit("skip curl extension not loaded");
+$handle=curl_init('http://127.0.0.1:37349/');
+curl_setopt($handle, CURLOPT_VERBOSE, true);
+curl_setopt($handle, CURLOPT_RETURNTRANSFER, true);
+if (!curl_setopt($handle, CURLOPT_STDERR, fopen("php://memory", "w+")))
+ die("skip fopencookie not supported on this platform");
+--FILE--
+<?php
+function do_stuff($url) {
+ $handle=curl_init('http://127.0.0.1:37349/');
+ curl_setopt($handle, CURLOPT_VERBOSE, true);
+ curl_setopt($handle, CURLOPT_RETURNTRANSFER, true);
+ curl_setopt($handle, CURLOPT_STDERR, $o = fopen($url, "w+"));
+ curl_exec($handle);
+ echo "About to rewind!\n";
+ rewind($o);
+ echo stream_get_contents($o);
+ return $o;
+}
+
+echo "temp stream (close after):\n";
+fclose(do_stuff("php://temp"));
+
+echo "\nmemory stream (close after):\n";
+fclose(do_stuff("php://memory"));
+
+echo "\nDone.\n";
+--EXPECT--
+temp stream (close after):
+About to rewind!
+* About to connect() to 127.0.0.1 port 37349 (#0)
+* Trying 127.0.0.1... * Connection refused
+* couldn't connect to host
+* Closing connection #0
+
+memory stream (close after):
+About to rewind!
+* About to connect() to 127.0.0.1 port 37349 (#0)
+* Trying 127.0.0.1... * Connection refused
+* couldn't connect to host
+* Closing connection #0
+
+Done.
diff --git a/main/streams/streams.c b/main/streams/streams.c index 023977d39e..e08c5e122c 100755 --- a/main/streams/streams.c +++ b/main/streams/streams.c @@ -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) { |