cataphract                               Mon, 15 Nov 2010 18:22:52 +0000

Revision: http://svn.php.net/viewvc?view=revision&revision=305379

Log:
- Fixed bug #52820 (writes to fopencookie FILE* not commited when seeking the
  stream).

Bug: http://bugs.php.net/52820 (Assigned) curl doesn't write to php://temp or 
/memory
      
Changed paths:
    U   php/php-src/branches/PHP_5_3/NEWS
    A   php/php-src/branches/PHP_5_3/ext/standard/tests/file/bug52820.phpt
    U   php/php-src/branches/PHP_5_3/main/streams/streams.c
    A   php/php-src/trunk/ext/standard/tests/file/bug52820.phpt
    U   php/php-src/trunk/main/streams/streams.c

Modified: php/php-src/branches/PHP_5_3/NEWS
===================================================================
--- php/php-src/branches/PHP_5_3/NEWS   2010-11-15 17:10:32 UTC (rev 305378)
+++ php/php-src/branches/PHP_5_3/NEWS   2010-11-15 18:22:52 UTC (rev 305379)
@@ -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).

Added: php/php-src/branches/PHP_5_3/ext/standard/tests/file/bug52820.phpt
===================================================================
--- php/php-src/branches/PHP_5_3/ext/standard/tests/file/bug52820.phpt          
                (rev 0)
+++ php/php-src/branches/PHP_5_3/ext/standard/tests/file/bug52820.phpt  
2010-11-15 18:22:52 UTC (rev 305379)
@@ -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.

Modified: php/php-src/branches/PHP_5_3/main/streams/streams.c
===================================================================
--- php/php-src/branches/PHP_5_3/main/streams/streams.c 2010-11-15 17:10:32 UTC 
(rev 305378)
+++ php/php-src/branches/PHP_5_3/main/streams/streams.c 2010-11-15 18:22:52 UTC 
(rev 305379)
@@ -1093,6 +1093,11 @@

 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) {

Added: php/php-src/trunk/ext/standard/tests/file/bug52820.phpt
===================================================================
--- php/php-src/trunk/ext/standard/tests/file/bug52820.phpt                     
        (rev 0)
+++ php/php-src/trunk/ext/standard/tests/file/bug52820.phpt     2010-11-15 
18:22:52 UTC (rev 305379)
@@ -0,0 +1,69 @@
+--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 "\ntemp stream (leak):\n";
+leak_variable(do_stuff("php://temp"), true);
+
+echo "\nmemory stream (leak):\n";
+leak_variable(do_stuff("php://memory"), true);
+
+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
+
+temp stream (leak):
+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 (leak):
+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.

Modified: php/php-src/trunk/main/streams/streams.c
===================================================================
--- php/php-src/trunk/main/streams/streams.c    2010-11-15 17:10:32 UTC (rev 
305378)
+++ php/php-src/trunk/main/streams/streams.c    2010-11-15 18:22:52 UTC (rev 
305379)
@@ -1164,6 +1164,11 @@

 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) {

-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to