mirror of
https://github.com/php/php-src.git
synced 2025-08-20 01:14:28 +02:00
Fixed bug #44818 (php://memory writeable when opened read only)
This commit is contained in:
parent
2fe765b5f4
commit
dec12b2549
2 changed files with 49 additions and 2 deletions
|
@ -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")) {
|
||||
|
|
37
ext/standard/tests/streams/bug44818.phpt
Normal file
37
ext/standard/tests/streams/bug44818.phpt
Normal file
|
@ -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"
|
Loading…
Add table
Add a link
Reference in a new issue