[php-src] master: Fix GH-13230: phpdbg use-after-free at shutdown
| From: | Ilia Alshanetsky | Date: | Wed, 11 Nov 2026 22:42:05 +0000 |
| Subject: | [php-src] master: Fix GH-13230: phpdbg use-after-free at shutdown | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-143608@lists.php.net to get a copy of this message | ||
Author: Ilia Alshanetsky (iliaal)
Date: 2026-11-11T17:41:27-05:00
Commit: https://github.com/php/php-src/commit/8eb02dbaa339613075d1c9db9f130eb7e4c8af73
Raw diff: https://github.com/php/php-src/commit/8eb02dbaa339613075d1c9db9f130eb7e4c8af73.diff
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.
The fix was reduced to these two changes by Kamil Tekiela.
Fixes GH-13230
Closes GH-22111
Changed paths:
M NEWS
M sapi/phpdbg/phpdbg_watch.c
M sapi/phpdbg/tests/bug73927.phpt
Diff:
diff --git a/NEWS b/NEWS
index ddcb2487e78d..5acaf162608b 100644
--- a/NEWS
+++ b/NEWS
@@ -114,6 +114,10 @@ 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).
+ (Kamil Tekiela, 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--
-<?php
-if (getenv('SKIP_ASAN')) {
- die("skip intentionally causes segfaults");
-}
-?>
--PHPDBG--
b 19
r