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.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'sapi/phpdbg/phpdbg.c') diff --git a/sapi/phpdbg/phpdbg.c b/sapi/phpdbg/phpdbg.c index 8207e36540..0f1f03625c 100644 --- a/sapi/phpdbg/phpdbg.c +++ b/sapi/phpdbg/phpdbg.c @@ -1341,10 +1341,12 @@ php_stream *phpdbg_stream_url_wrap_php(php_stream_wrapper *wrapper, const char * if (!strncasecmp(path, "stdin", 6) && PHPDBG_G(stdin_file)) { php_stream *stream = php_stream_fopen_from_fd(dup(fileno(PHPDBG_G(stdin_file))), "r", NULL); #ifdef PHP_WIN32 - zval *blocking_pipes = php_stream_context_get_option(context, "pipe", "blocking"); - if (blocking_pipes) { - convert_to_long(blocking_pipes); - php_stream_set_option(stream, PHP_STREAM_OPTION_PIPE_BLOCKING, Z_LVAL_P(blocking_pipes), NULL); + if (context != NULL) { + zval *blocking_pipes = php_stream_context_get_option(context, "pipe", "blocking"); + if (blocking_pipes) { + convert_to_long(blocking_pipes); + php_stream_set_option(stream, PHP_STREAM_OPTION_PIPE_BLOCKING, Z_LVAL_P(blocking_pipes), NULL); + } } #endif return stream; @@ -2059,6 +2061,8 @@ phpdbg_out: phpdbg_out: #endif + phpdbg_purge_watchpoint_tree(); + if (first_command) { free(first_command); first_command = NULL; -- cgit v1.2.1