Skip to content

ext/standard: fix use-after-free and resource reuse from write_seek_mode - #25401

Open
DanielEScherzer wants to merge 1 commit into
php:PHP-8.6from
DanielEScherzer:filter-write_seek_mode
Open

DanielEScherzer wants to merge 1 commit into
php:PHP-8.6from
DanielEScherzer:filter-write_seek_mode

Conversation

@DanielEScherzer

Copy link
Copy Markdown
Member

When converting an object into a string for write_seek_mode, don't allow the target stream to be closed, otherwise it could trigger a use-after-free or silently reuse the stream.

…mode`

When converting an object into a string for `write_seek_mode`, don't allow the
target stream to be closed, otherwise it could trigger a use-after-free or
silently reuse the stream.
}

if (read_write & PHP_STREAM_FILTER_WRITE) {
bool originally_no_fclose = stream->flags & PHP_STREAM_FLAG_NO_FCLOSE;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The read chain has the same problem, stream_filter_append($s, 'convert.base64-encode', STREAM_FILTER_READ, ['write_seek_mode' => $obj]) still frees the stream, so the guard needs to wrap both branches.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants