lbarnaud                Tue Nov 11 00:44:37 2008 UTC

  Added files:                 
    /php-src/ext/standard/tests/streams bug44818.phpt 

  Modified files:              
    /php-src/ext/standard       php_fopen_wrapper.c 
  Log:
  Fixed bug #44818 (php://memory writeable when opened read only)
  
  
http://cvs.php.net/viewvc.cgi/php-src/ext/standard/php_fopen_wrapper.c?r1=1.64&r2=1.65&diff_format=u
Index: php-src/ext/standard/php_fopen_wrapper.c
diff -u php-src/ext/standard/php_fopen_wrapper.c:1.64 
php-src/ext/standard/php_fopen_wrapper.c:1.65
--- php-src/ext/standard/php_fopen_wrapper.c:1.64       Tue Nov  4 21:04:28 2008
+++ php-src/ext/standard/php_fopen_wrapper.c    Tue Nov 11 00:44:36 2008
@@ -17,7 +17,7 @@
    |          Hartmut Holzgraefe <[EMAIL PROTECTED]>                       |
    +----------------------------------------------------------------------+
  */
-/* $Id: php_fopen_wrapper.c,v 1.64 2008/11/04 21:04:28 lbarnaud Exp $ */
+/* $Id: php_fopen_wrapper.c,v 1.65 2008/11/11 00:44:36 lbarnaud Exp $ */
 
 #include <stdio.h>
 #include <stdlib.h>
@@ -186,11 +186,21 @@
                                return NULL;
                        }
                }
-               return php_stream_temp_create(TEMP_STREAM_DEFAULT, max_memory); 
        
+               if (strpbrk(mode, "wa+")) {
+                       mode_rw = TEMP_STREAM_DEFAULT;
+               } else {
+                       mode_rw = TEMP_STREAM_READONLY;
+               }
+               return php_stream_temp_create(mode_rw, max_memory);             
        }
        
        if (!strcasecmp(path, "memory")) {
-               return php_stream_memory_create(TEMP_STREAM_DEFAULT);
+               if (strpbrk(mode, "wa+")) {
+                       mode_rw = TEMP_STREAM_DEFAULT;
+               } else {
+                       mode_rw = TEMP_STREAM_READONLY;
+               }
+               return php_stream_memory_create(mode_rw);
        }
        
        if (!strcasecmp(path, "output")) {

http://cvs.php.net/viewvc.cgi/php-src/ext/standard/tests/streams/bug44818.phpt?view=markup&rev=1.1
Index: php-src/ext/standard/tests/streams/bug44818.phpt
+++ php-src/ext/standard/tests/streams/bug44818.phpt
--TEST--
Bug #44818 (php://memory writeable when opened read only)
--FILE--
<?php
function test($url, $mode) {
        echo "$url, $mode\n";
        $fd = fopen($url, $mode);
        var_dump($fd, fwrite($fd, b"foo"));
        var_dump(fseek($fd, 0, SEEK_SET), fread($fd, 3));
        fclose($fd);
}
test("php://memory","r");
test("php://memory","r+");
test("php://temp","r");
test("php://temp","w");
?>
--EXPECTF--
php://memory, r
resource(%d) of type (stream)
int(0)
int(0)
string(0) ""
php://memory, r+
resource(%d) of type (stream)
int(3)
int(0)
string(3) "foo"
php://temp, r
resource(%d) of type (stream)
int(0)
int(0)
string(0) ""
php://temp, w
resource(%d) of type (stream)
int(3)
int(0)
string(3) "foo"



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

Reply via email to