Skip to content

Commit

Permalink
Fix crashes in function registration + test
Browse files Browse the repository at this point in the history
Internal function won't need their refcount increased as they outlive
the debugger session, and userland functions won't be unloaded either.
So no refcount management is necessary for registered functions.
  • Loading branch information
nielsdos committed Jan 6, 2025
1 parent 4768348 commit 1235c74
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 7 deletions.
3 changes: 3 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ PHP NEWS
- Intl:
. Fixed bug GH-11874 (intl causing segfault in docker images). (nielsdos)

- PHPDBG:
. Fix crashes in function registration + test. (nielsdos, Girgias)

- SNMP:
. Fixed bug GH-17330 (SNMP::setSecurity segfault on closed session).
(David Carlier)
Expand Down
7 changes: 1 addition & 6 deletions sapi/phpdbg/phpdbg.c
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,6 @@ static void php_phpdbg_destroy_bp_condition(zval *data) /* {{{ */
efree(brake);
} /* }}} */

static void php_phpdbg_destroy_registered(zval *data) /* {{{ */
{
zend_function_dtor(data);
} /* }}} */

static void php_phpdbg_destroy_file_source(zval *data) /* {{{ */
{
phpdbg_file_source *source = (phpdbg_file_source *) Z_PTR_P(data);
Expand Down Expand Up @@ -163,7 +158,7 @@ static PHP_MINIT_FUNCTION(phpdbg) /* {{{ */
zend_hash_init(&PHPDBG_G(bp)[PHPDBG_BREAK_MAP], 8, NULL, NULL, 0);

zend_hash_init(&PHPDBG_G(seek), 8, NULL, NULL, 0);
zend_hash_init(&PHPDBG_G(registered), 8, NULL, php_phpdbg_destroy_registered, 0);
zend_hash_init(&PHPDBG_G(registered), 8, NULL, NULL, true);

zend_hash_init(&PHPDBG_G(file_sources), 0, NULL, php_phpdbg_destroy_file_source, 0);
phpdbg_setup_watchpoints();
Expand Down
1 change: 0 additions & 1 deletion sapi/phpdbg/phpdbg_prompt.c
Original file line number Diff line number Diff line change
Expand Up @@ -1424,7 +1424,6 @@ PHPDBG_COMMAND(register) /* {{{ */
if (!zend_hash_str_exists(&PHPDBG_G(registered), lcname, lcname_len)) {
if ((function = zend_hash_str_find_ptr(EG(function_table), lcname, lcname_len))) {
zend_hash_str_update_ptr(&PHPDBG_G(registered), lcname, lcname_len, function);
function_add_ref(function);

phpdbg_notice("Registered %s", lcname);
} else {
Expand Down
30 changes: 30 additions & 0 deletions sapi/phpdbg/tests/register_function.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
--TEST--
Test registering of functions
--PHPDBG--
R testfunc
testfunc 1 2 3
R var_dump
var_dump foo
q
--FILE--
<?php
function testfunc() {
var_dump(func_get_args());
}
?>
--EXPECTF--
[Successful compilation of %s]
prompt> [Registered testfunc]
prompt> array(3) {
[0]=>
int(1)
[1]=>
int(2)
[2]=>
int(3)
}

prompt> [Registered var_dump]
prompt> string(3) "foo"

prompt>

0 comments on commit 1235c74

Please sign in to comment.