]> granicus.if.org Git - php/commitdiff
MFH: Fixed bug #44818 (php://memory writeable when opened read only)
authorArnaud Le Blanc <lbarnaud@php.net>
Tue, 11 Nov 2008 00:45:36 +0000 (00:45 +0000)
committerArnaud Le Blanc <lbarnaud@php.net>
Tue, 11 Nov 2008 00:45:36 +0000 (00:45 +0000)
NEWS
ext/standard/php_fopen_wrapper.c
ext/standard/tests/streams/bug44818.phpt [new file with mode: 0644]

diff --git a/NEWS b/NEWS
index 75981efda50e9bb44d7599e5850b5940faf4fb66..93f260962011f87f40a5a3957363ee1a5316b34e 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -6,6 +6,7 @@ PHP                                                                        NEWS
 
 - Fixed bug #46521 (Curl ZTS OpenSSL, error in config.m4 fragment).
   (jd at cpanel dot net)
+- Fixed bug #44818 (php://memory writeable when opened read only). (Arnaud)
 - Fixed bug #30312 (sybase_unbuffered_query calls). (Timm)
 
 06 Nov 2008, PHP 5.2.7RC3
index fcf6078a462cf2c77e7345c499f881e514490200..3d42b18a49b5087b8c6b37aec4149d66a881b49a 100644 (file)
@@ -176,11 +176,21 @@ php_stream * php_stream_url_wrap_php(php_stream_wrapper *wrapper, char *path, ch
                                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")) {
diff --git a/ext/standard/tests/streams/bug44818.phpt b/ext/standard/tests/streams/bug44818.phpt
new file mode 100644 (file)
index 0000000..628f64e
--- /dev/null
@@ -0,0 +1,37 @@
+--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"