From dec12b25495c2cc8271f1549867aef4f11a16a1b Mon Sep 17 00:00:00 2001 From: Arnaud Le Blanc Date: Tue, 11 Nov 2008 00:44:36 +0000 Subject: [PATCH] Fixed bug #44818 (php://memory writeable when opened read only) --- ext/standard/php_fopen_wrapper.c | 14 +++++++-- ext/standard/tests/streams/bug44818.phpt | 37 ++++++++++++++++++++++++ 2 files changed, 49 insertions(+), 2 deletions(-) create mode 100644 ext/standard/tests/streams/bug44818.phpt diff --git a/ext/standard/php_fopen_wrapper.c b/ext/standard/php_fopen_wrapper.c index 3f88dcaffc..fffc6fe6e3 100644 --- a/ext/standard/php_fopen_wrapper.c +++ b/ext/standard/php_fopen_wrapper.c @@ -186,11 +186,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 index 0000000000..628f64e341 --- /dev/null +++ b/ext/standard/tests/streams/bug44818.phpt @@ -0,0 +1,37 @@ +--TEST-- +Bug #44818 (php://memory writeable when opened read only) +--FILE-- + +--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" -- 2.50.1