Skip to content

Fix zval type info when stripping leading backslash from AST names - #263

Merged
nikic merged 1 commit into
nikic:masterfrom
iliaal:fix/ast-name-interned-string
Nov 29, 2026
Merged

nikic merged 1 commit into
nikic:masterfrom
iliaal:fix/ast-name-interned-string

Conversation

@iliaal

@iliaal iliaal commented Nov 28, 2026 •

Copy link
Copy Markdown
Contributor

In ast_name_to_zval(), stripping a leading backslash assigned Z_STR_P(name) = new_name without updating the zval type info. When the original string is interned (such as a single-byte backslash in a heredoc), the zval kept IS_INTERNED_STRING_EX while pointing to a heap-allocated zend_string, causing a use-after-free on concatenation and leaking the string on destruction. Use ZVAL_NEW_STR() instead so the zval type info matches the new string.

Comment thread ast.c Resolved
Comment thread tests/name_node_interned_backslash.phpt Resolved
In ast_name_to_zval(), stripping a leading backslash assigned
Z_STR_P(name) = new_name without updating the zval type info. When the
original string is interned (such as a single-byte backslash in a
heredoc), the zval kept IS_INTERNED_STRING_EX while pointing to a
heap-allocated zend_string, causing a use-after-free on concatenation
and leaking the string on destruction. Use ZVAL_NEW_STR() so the zval
type info matches the new string.
@iliaal
iliaal force-pushed the fix/ast-name-interned-string branch from b6262d8 to 8b65af9 Compare November 29, 2026 16:46
@nikic
nikic merged commit 208c294 into nikic:master Nov 29, 2026
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants