Skip to content

Fix GH-22490: NULL deref for a pipe on the lhs of ??=#22494

Open
iliaal wants to merge 1 commit into
php:masterfrom
iliaal:fix/gh-22490-pipe-coalesce-memoize
Open

Fix GH-22490: NULL deref for a pipe on the lhs of ??=#22494
iliaal wants to merge 1 commit into
php:masterfrom
iliaal:fix/gh-22490-pipe-coalesce-memoize

Conversation

@iliaal

@iliaal iliaal commented Jun 27, 2026

Copy link
Copy Markdown
Contributor

A pipe expression on the left-hand side of ??=, e.g. (1 |> f(...))->g ??= 2, crashes the compiler with a NULL pointer dereference in zend_compile_memoized_expr. The coalesce-assign LHS is compiled twice and call results are memoized by AST-node pointer, but zend_compile_pipe desugars the pipe into a freshly allocated call node on each pass, so the fetch pass looks up a pointer the compile pass never stored. Memoizing the whole pipe under its stable original node, consistent with zend_is_call(), makes the pipe compile once and the fetch pass reuse the result.

Fixes #22490

@devnexen devnexen left a comment

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.

lgtm, you might need a more refined commit title though

@iliaal iliaal force-pushed the fix/gh-22490-pipe-coalesce-memoize branch from bc6aa84 to 73b86f9 Compare June 28, 2026 11:20
@iliaal

iliaal commented Jun 28, 2026

Copy link
Copy Markdown
Contributor Author

Renamed for clarity.

@devnexen

devnexen commented Jun 28, 2026

Copy link
Copy Markdown
Member

Renamed for clarity.

More like : Fix GH-22490:... or Zend:...

zend_compile_var_inner did not route ZEND_AST_PIPE through
zend_compile_memoized_expr, so a pipe on the left-hand side of ??= was
recompiled during the FETCH pass. zend_compile_pipe synthesizes a fresh
call node on each pass, so the memoized-result lookup keyed by that node
returned NULL and was dereferenced. Memoize the pipe like the other call
kinds zend_is_call() already recognizes.

Fixes phpGH-22490
@iliaal iliaal force-pushed the fix/gh-22490-pipe-coalesce-memoize branch from 73b86f9 to e7aa318 Compare June 28, 2026 11:31
@iliaal iliaal changed the title Memoize pipe operator on the lhs of coalesce assignment Fix GH-22490: NULL deref for a pipe on the lhs of ??= Jun 28, 2026
@iliaal

iliaal commented Jun 28, 2026

Copy link
Copy Markdown
Contributor Author

Done, retitled the PR and commit to Fix GH-22490:.

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.

Null pointer dereference in zend_hash_index_find_ptr

2 participants