From 88c00cb11f6f38b3845d5ab2fd4cbf37228c0b96 Mon Sep 17 00:00:00 2001 From: Ilia Alshanetsky Date: Mon, 9 Nov 2026 08:32:46 -0500 Subject: [PATCH] Fix GH-13230: phpdbg use-after-free at shutdown phpdbg_clean_watch_element() left element->watch pointing at the watchpoint that phpdbg_remove_watchpoint() had just freed, so a later phpdbg_backup_watch_element() on the same chain copied from freed memory. Clear the pointer and skip the backup for a detached element. Drop the SKIP_ASAN guard from bug73927.phpt, which reproduces the read. Fixes GH-13230 --- NEWS | 3 +++ sapi/phpdbg/phpdbg_watch.c | 4 ++++ sapi/phpdbg/tests/bug73927.phpt | 6 ------ 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/NEWS b/NEWS index 5a865955281d..84b9c6deb9b6 100644 --- a/NEWS +++ b/NEWS @@ -111,6 +111,9 @@ PHP NEWS - PGSQL: . Fixed pg_lo_write() rejecting data containing null bytes. (Ilia Alshanetsky) +- phpdbg: + . Fixed bug GH-13230 (use-after-free at phpdbg shutdown). (Ilia Alshanetsky) + - Posix: . Reverted the validity check on the flags argument of posix_access(). (David Carlier) diff --git a/sapi/phpdbg/phpdbg_watch.c b/sapi/phpdbg/phpdbg_watch.c index a2e39e15a6ca..e617a7b73cb3 100644 --- a/sapi/phpdbg/phpdbg_watch.c +++ b/sapi/phpdbg/phpdbg_watch.c @@ -979,6 +979,9 @@ void phpdbg_remove_watch_element(phpdbg_watch_element *element) { } void phpdbg_backup_watch_element(phpdbg_watch_element *element) { + if (!element->watch) { + return; + } memcpy(&element->backup, &element->watch->backup, /* element->watch->size */ sizeof(element->backup)); } @@ -1097,6 +1100,7 @@ void phpdbg_clean_watch_element(phpdbg_watch_element *element) { if (zend_hash_num_elements(elements) == 0) { phpdbg_remove_watchpoint(element->watch); } + element->watch = NULL; } } diff --git a/sapi/phpdbg/tests/bug73927.phpt b/sapi/phpdbg/tests/bug73927.phpt index bb54f4e17617..81a1d2fa47fe 100644 --- a/sapi/phpdbg/tests/bug73927.phpt +++ b/sapi/phpdbg/tests/bug73927.phpt @@ -1,11 +1,5 @@ --TEST-- Bug #73927 (phpdbg fails with windows error prompt at "watch array") ---SKIPIF-- - --PHPDBG-- b 19 r