Skip to content

Commit f79bd08

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

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
@@ -648,6 +648,7 @@ static ssize_t php_userstreamop_read(php_stream *stream, char *buf, size_t count
648648
}
649649

650650
if (!try_convert_to_string(&retval)) {
651+
zval_ptr_dtor(&retval);
651652
return -1;
652653
}
653654

0 commit comments

Comments
 (0)