Skip to content

Commit b976ad0

Browse files
committed
Merge branch 'PHP-8.1'
* PHP-8.1: Fix leak of invalid stream_read() return value
2 parents 9800845 + f79bd08 commit b976ad0

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
--TEST--
2+
Returning an object from stream_read() is invalid, but should not leak
3+
--FILE--
4+
<?php
5+
class MyStream {
6+
function stream_open() {
7+
return true;
8+
}
9+
function stream_stat() {
10+
return false;
11+
}
12+
function stream_read() {
13+
return new stdClass;
14+
}
15+
}
16+
stream_wrapper_register('mystream', MyStream::class);
17+
try {
18+
var_dump(file_get_contents('mystream://'));
19+
} catch (Error $e) {
20+
echo $e->getMessage(), "\n";
21+
}
22+
?>
23+
--EXPECT--
24+
Object of class stdClass could not be converted to string

main/streams/userspace.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -639,6 +639,7 @@ static ssize_t php_userstreamop_read(php_stream *stream, char *buf, size_t count
639639
}
640640

641641
if (!try_convert_to_string(&retval)) {
642+
zval_ptr_dtor(&retval);
642643
return -1;
643644
}
644645

0 commit comments

Comments
 (0)