Skip to content

Commit

Permalink
Fix leak of invalid stream_read() return value
Browse files Browse the repository at this point in the history
Fixes oss-fuzz 6225190686687232 (part of #38542).
  • Loading branch information
nikic committed Sep 28, 2021
1 parent 6154aa6 commit 2f798d9
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
24 changes: 24 additions & 0 deletions ext/standard/tests/streams/stream_read_object_return.phpt
@@ -0,0 +1,24 @@
--TEST--
Returning an object from stream_read() is invalid, but should not leak
--FILE--
<?php
class MyStream {
function stream_open() {
return true;
}
function stream_stat() {
return false;
}
function stream_read() {
return new stdClass;
}
}
stream_wrapper_register('mystream', MyStream::class);
try {
var_dump(file_get_contents('mystream://'));
} catch (Error $e) {
echo $e->getMessage(), "\n";
}
?>
--EXPECT--
Object of class stdClass could not be converted to string
1 change: 1 addition & 0 deletions main/streams/userspace.c
Expand Up @@ -648,6 +648,7 @@ static ssize_t php_userstreamop_read(php_stream *stream, char *buf, size_t count
}

if (!try_convert_to_string(&retval)) {
zval_ptr_dtor(&retval);
return -1;
}

Expand Down

0 comments on commit 2f798d9

Please sign in to comment.