Skip to content

Fix GH-22480: phpdbg use-after-free re-watching a watched variable#22493

Open
iliaal wants to merge 1 commit into
php:masterfrom
iliaal:fix/gh-22480-phpdbg-watch-uaf
Open

Fix GH-22480: phpdbg use-after-free re-watching a watched variable#22493
iliaal wants to merge 1 commit into
php:masterfrom
iliaal:fix/gh-22480-phpdbg-watch-uaf

Conversation

@iliaal

@iliaal iliaal commented Jun 27, 2026

Copy link
Copy Markdown
Contributor

Fixes #22480

phpdbg_add_watch_element() frees the passed element and returns the existing one when the variable is already watched, but several callers kept using the freed pointer, so re-watching a variable was a use-after-free. The two reported derefs are not the whole bug: with only the proposed two-line capture, w a $a typed twice still crashes, relocated to a later interned-string read. This reports the duplicate back through the parse callback so the wrapper registers nothing, and rejects a recursive watch's hashtable element that collides with an existing watch, at creation and recreation, instead of freeing a still-referenced one.

phpdbg_add_watch_element() frees the passed element and returns the
existing one when the variable is already watched, but several callers
kept using the freed pointer, so re-watching a variable was a
use-after-free in more places than the two reported. Report the duplicate
back through the parse callback and register nothing, and reject a
recursive watch's hashtable element that collides with an existing watch,
at creation and recreation, rather than freeing a still-referenced one. A
recursive watch over an already-array-watched variable now watches only
the root and skips the shared hashtable.

Fixes phpGH-22480
@Girgias

Girgias commented Jun 28, 2026

Copy link
Copy Markdown
Member

I don't know PHPDBG nor have the time to learn how it works rn.

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.

[phpdbg] Multiple Use-After-Free bugs in watchpoint management due to ignored return values

2 participants