Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,10 @@ PHP NEWS
. Fixed bug GH-25722 (phar_archive_delref() double free on shared archive at
shutdown). (David Carlier)

- PHPDBG:
. Fixed use-after-free with recursive watchpoints on arrays when the watch is
deleted or the script ends. (Ilia Alshanetsky)

- POSIX:
. Fixed bug GH-25530 (posix_get_last_error() returns an error from a
previous request). (Artem Ukrainskiy)
Expand Down
24 changes: 12 additions & 12 deletions sapi/phpdbg/phpdbg_watch.c
Original file line number Diff line number Diff line change
Expand Up @@ -960,20 +960,20 @@ void phpdbg_remove_watch_element(phpdbg_watch_element *element) {
phpdbg_clean_watch_element(cur);
phpdbg_free_watch_element(cur);
}
while (child) {
phpdbg_watch_element *cur = child;
child = child->child;
if (cur->flags & PHPDBG_WATCH_RECURSIVE_ROOT) {
phpdbg_remove_watch_element_recursively(cur);
child = NULL;
} else {
phpdbg_clean_watch_element(cur);
}
phpdbg_free_watch_element(cur);
}
if (element->flags & PHPDBG_WATCH_RECURSIVE_ROOT) {
phpdbg_remove_watch_element_recursively(element);
} else {
while (child) {
phpdbg_watch_element *cur = child;
child = child->child;
if (cur->flags & PHPDBG_WATCH_RECURSIVE_ROOT) {
phpdbg_remove_watch_element_recursively(cur);
child = NULL;
} else {
phpdbg_clean_watch_element(cur);
}
phpdbg_free_watch_element(cur);
}
phpdbg_clean_watch_element(element);
}
zend_hash_index_del(&PHPDBG_G(watch_elements), element->id);
Expand Down Expand Up @@ -1479,7 +1479,7 @@ static int phpdbg_watchpoint_parse_wrapper(char *name, size_t namelen, char *key
PHPDBG_G(watch_tmp)->child = element;
}

if (element->child) {
if (element->child && !(element->flags & PHPDBG_WATCH_RECURSIVE_ROOT)) {
element = element->child;
}

Expand Down
2 changes: 1 addition & 1 deletion sapi/phpdbg/tests/gh22480_2.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ prompt> [Breakpoint #0 added at %s:5]
prompt> [Breakpoint #0 at %s:5, hits: 1]
>00005: $a['x'] = 2;
00006:
prompt> [Added watchpoint #0 for $a[]]
prompt> [Added recursive watchpoint #0 for $a]
prompt> [$a[x] is already being watched]
prompt> [Breaking on watchpoint $a]
Old value%s
Expand Down
32 changes: 32 additions & 0 deletions sapi/phpdbg/tests/watch_008.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
--TEST--
Recursive watchpoint on an array is released with its children at shutdown
--PHPDBG--
b 5
r
w $x
w r $a
c
c
q
--EXPECTF--
[Successful compilation of %s]
prompt> [Breakpoint #0 added at %s:5]
prompt> [Breakpoint #0 at %s:5, hits: 1]
>00005: $x = 2;
00006:
prompt> [Added watchpoint #0 for $x]
prompt> [Added recursive watchpoint #1 for $a]
prompt> [Breaking on watchpoint $x]
Old value: 1
New value: 2
>00006:
prompt> [$x has been removed, removing watchpoint]
[$a has been removed, removing watchpoint recursively]
[Script ended normally]
prompt>
--FILE--
<?php

$x = 1;
$a = [1, [2]];
$x = 2;
32 changes: 32 additions & 0 deletions sapi/phpdbg/tests/watch_009.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
--TEST--
Deleting a recursive watchpoint after its variable became an array
--PHPDBG--
b 4
r
w r $b
c
w d 0
c
q
--EXPECTF--
[Successful compilation of %s]
prompt> [Breakpoint #0 added at %s:4]
prompt> [Breakpoint #0 at %s:4, hits: 1]
>00004: $b = [1, [2]];
00005: $c = 1;
00006:
prompt> [Added recursive watchpoint #0 for $b]
prompt> [Breaking on watchpoint $b]
Old value:
New value: Array ([0] => 1,[1] => Array ([0] => 2))
>00005: $c = 1;
00006:
prompt> [Removed watchpoint 0]
prompt> [Script ended normally]
prompt>
--FILE--
<?php

$b = null;
$b = [1, [2]];
$c = 1;
Loading