From 8cb15f6203da38ccde8622e317b1d0818ce5f605 Mon Sep 17 00:00:00 2001 From: Niels Dossche <7771979+nielsdos@users.noreply.github.com> Date: Mon, 6 Jan 2025 19:28:21 +0100 Subject: [PATCH] Fix crashes in function registration + test 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. --- sapi/phpdbg/phpdbg.c | 7 +----- sapi/phpdbg/phpdbg_prompt.c | 1 - sapi/phpdbg/tests/register_function.phpt | 30 ++++++++++++++++++++++++ 3 files changed, 31 insertions(+), 7 deletions(-) create mode 100644 sapi/phpdbg/tests/register_function.phpt diff --git a/sapi/phpdbg/phpdbg.c b/sapi/phpdbg/phpdbg.c index 2d0f148fd7a..6f81a7a7c05 100644 --- a/sapi/phpdbg/phpdbg.c +++ b/sapi/phpdbg/phpdbg.c @@ -90,11 +90,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); @@ -164,7 +159,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(); diff --git a/sapi/phpdbg/phpdbg_prompt.c b/sapi/phpdbg/phpdbg_prompt.c index 6333fdcb765..d47f967e724 100644 --- a/sapi/phpdbg/phpdbg_prompt.c +++ b/sapi/phpdbg/phpdbg_prompt.c @@ -1420,7 +1420,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 { diff --git a/sapi/phpdbg/tests/register_function.phpt b/sapi/phpdbg/tests/register_function.phpt new file mode 100644 index 00000000000..bf4f1615d32 --- /dev/null +++ b/sapi/phpdbg/tests/register_function.phpt @@ -0,0 +1,30 @@ +--TEST-- +Test registering of functions +--PHPDBG-- +R testfunc +testfunc 1 2 3 +R var_dump +var_dump foo +q +--FILE-- + +--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>