From 8483a21f29fbfd8d86ddf2eb2b7db0ae0b462949 Mon Sep 17 00:00:00 2001 From: "Christoph M. Becker" Date: Mon, 25 May 2020 19:12:24 +0200 Subject: Fix several mostly Windows related phpdbg bugs * Properly initialize PHPDBG_G(watch_tmp) Otherwise that may cause segfaults in ZTS builds. * Deactivate potentially remaining watchpoints after REPL Otherwise the memory could still be protected, resulting in segfaults during shutdown. * NULL zend_handlers_table after freeing As of commit 4130fe4[1], the `zend_handlers_table` is explicitly freed in the `zend_vm_dtor()`. Since phpdbg (and maybe some other SAPIs) may restart the engine afterwards, we have to make sure that the table is also NULLed. * Only set context option if there is a context In other words, we must not follow the null pointer. * Cater to file handles without attached console File handles do not necessarily have an attached console (for instance, pipes do not), in which case `GetConsoleScreenBufferInfo()` fails. In this case we set a default value (`40`) for lines like on other systems. [1] --- sapi/phpdbg/phpdbg_watch.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'sapi/phpdbg/phpdbg_watch.c') diff --git a/sapi/phpdbg/phpdbg_watch.c b/sapi/phpdbg/phpdbg_watch.c index d9f9f8673f..317aa9666a 100644 --- a/sapi/phpdbg/phpdbg_watch.c +++ b/sapi/phpdbg/phpdbg_watch.c @@ -1406,6 +1406,8 @@ void phpdbg_setup_watchpoints(void) { zend_hash_init(PHPDBG_G(watchlist_mem), phpdbg_pagesize / (sizeof(Bucket) + sizeof(uint32_t)), NULL, NULL, 1); PHPDBG_G(watchlist_mem_backup) = malloc(phpdbg_pagesize > sizeof(HashTable) ? phpdbg_pagesize : sizeof(HashTable)); zend_hash_init(PHPDBG_G(watchlist_mem_backup), phpdbg_pagesize / (sizeof(Bucket) + sizeof(uint32_t)), NULL, NULL, 1); + + PHPDBG_G(watch_tmp) = NULL; } void phpdbg_destroy_watchpoints(void) { @@ -1433,3 +1435,13 @@ void phpdbg_destroy_watchpoints(void) { zend_hash_destroy(PHPDBG_G(watchlist_mem_backup)); free(PHPDBG_G(watchlist_mem_backup)); } + +void phpdbg_purge_watchpoint_tree(void) { + phpdbg_btree_position pos; + phpdbg_btree_result *res; + + pos = phpdbg_btree_find_between(&PHPDBG_G(watchpoint_tree), 0, -1); + while ((res = phpdbg_btree_next(&pos))) { + phpdbg_deactivate_watchpoint(res->ptr); + } +} -- cgit v1.2.1