diff --git a/sapi/phpdbg/config.m4 b/sapi/phpdbg/config.m4 index e78c012e88c..dd282c2cbd8 100644 --- a/sapi/phpdbg/config.m4 +++ b/sapi/phpdbg/config.m4 @@ -5,12 +5,6 @@ PHP_ARG_ENABLE([phpdbg], [yes], [yes]) -PHP_ARG_ENABLE([phpdbg-webhelper], - [for phpdbg web SAPI support], - [AS_HELP_STRING([--enable-phpdbg-webhelper], - [Build phpdbg web SAPI support])], - [no]) - PHP_ARG_ENABLE([phpdbg-debug], [for phpdbg debug build], [AS_HELP_STRING([--enable-phpdbg-debug], @@ -36,7 +30,7 @@ if test "$BUILD_PHPDBG" = "" && test "$PHP_PHPDBG" != "no"; then fi PHP_PHPDBG_CFLAGS="-D_GNU_SOURCE -DZEND_ENABLE_STATIC_TSRMLS_CACHE=1" - PHP_PHPDBG_FILES="phpdbg.c phpdbg_parser.c phpdbg_lexer.c phpdbg_prompt.c phpdbg_help.c phpdbg_break.c phpdbg_print.c phpdbg_bp.c phpdbg_opcode.c phpdbg_list.c phpdbg_utils.c phpdbg_info.c phpdbg_cmd.c phpdbg_set.c phpdbg_frame.c phpdbg_watch.c phpdbg_btree.c phpdbg_sigsafe.c phpdbg_wait.c phpdbg_io.c phpdbg_eol.c phpdbg_out.c" + PHP_PHPDBG_FILES="phpdbg.c phpdbg_parser.c phpdbg_lexer.c phpdbg_prompt.c phpdbg_help.c phpdbg_break.c phpdbg_print.c phpdbg_bp.c phpdbg_opcode.c phpdbg_list.c phpdbg_utils.c phpdbg_info.c phpdbg_cmd.c phpdbg_set.c phpdbg_frame.c phpdbg_watch.c phpdbg_btree.c phpdbg_sigsafe.c phpdbg_io.c phpdbg_eol.c phpdbg_out.c" AC_MSG_CHECKING([for phpdbg and readline integration]) if test "$PHP_PHPDBG_READLINE" = "yes"; then @@ -90,7 +84,3 @@ if test "$BUILD_PHPDBG" = "" && test "$PHP_PHPDBG" != "no"; then PHP_OUTPUT(sapi/phpdbg/phpdbg.1) fi - -if test "$PHP_PHPDBG_WEBHELPER" != "no"; then - PHP_NEW_EXTENSION(phpdbg_webhelper, phpdbg_rinit_hook.c phpdbg_webdata_transfer.c, $ext_shared) -fi diff --git a/sapi/phpdbg/config.w32 b/sapi/phpdbg/config.w32 index 9aca03dff6a..49e18206696 100644 --- a/sapi/phpdbg/config.w32 +++ b/sapi/phpdbg/config.w32 @@ -1,18 +1,16 @@ ARG_ENABLE('phpdbg', 'Build phpdbg', 'no'); ARG_ENABLE('phpdbgs', 'Build phpdbg shared', 'no'); -ARG_ENABLE('phpdbg-webhelper', 'Build phpdbg webhelper', 'yes'); PHPDBG_SOURCES='phpdbg.c phpdbg_prompt.c phpdbg_cmd.c phpdbg_info.c phpdbg_help.c phpdbg_break.c ' + 'phpdbg_print.c phpdbg_bp.c phpdbg_opcode.c phpdbg_list.c phpdbg_utils.c ' + 'phpdbg_set.c phpdbg_frame.c phpdbg_watch.c phpdbg_win.c phpdbg_btree.c '+ - 'phpdbg_parser.c phpdbg_lexer.c phpdbg_sigsafe.c phpdbg_wait.c phpdbg_io.c ' + + 'phpdbg_parser.c phpdbg_lexer.c phpdbg_sigsafe.c phpdbg_io.c ' + 'phpdbg_sigio_win32.c phpdbg_eol.c phpdbg_out.c'; PHPDBG_DLL='php' + PHP_VERSION + 'phpdbg.dll'; PHPDBG_EXE='phpdbg.exe'; PHPDBG_CFLAGS='/DZEND_ENABLE_STATIC_TSRMLS_CACHE=1'; var PHP_PHPDBG_PGO = false; -var PHP_PHPDBG_WEBHELPER_PGO = false; var PHP_PHPDBGS_PGO = false; if (PHP_PHPDBG == "yes") { @@ -20,10 +18,6 @@ if (PHP_PHPDBG == "yes") { ADD_FLAG("LIBS_PHPDBG", "ws2_32.lib user32.lib"); ADD_FLAG("CFLAGS_PHPDBG", "/D YY_NO_UNISTD_H"); ADD_FLAG("LDFLAGS_PHPDBG", "/stack:8388608"); - - if (PHP_PHPDBG_WEBHELPER == "yes") { - EXTENSION('phpdbg_webhelper', 'phpdbg_rinit_hook.c phpdbg_webdata_transfer.c'); - } } if (PHP_PHPDBGS == "yes") { diff --git a/sapi/phpdbg/phpdbg.c b/sapi/phpdbg/phpdbg.c index 4d37cc94499..d8d205cf143 100644 --- a/sapi/phpdbg/phpdbg.c +++ b/sapi/phpdbg/phpdbg.c @@ -70,7 +70,6 @@ static PHP_INI_MH(OnUpdateEol) } PHP_INI_BEGIN() - STD_PHP_INI_ENTRY("phpdbg.path", "", PHP_INI_SYSTEM | PHP_INI_PERDIR, OnUpdateString, socket_path, zend_phpdbg_globals, phpdbg_globals) STD_PHP_INI_ENTRY("phpdbg.eol", "2", PHP_INI_ALL, OnUpdateEol, eol, zend_phpdbg_globals, phpdbg_globals) PHP_INI_END() @@ -157,8 +156,6 @@ static inline void php_phpdbg_globals_ctor(zend_phpdbg_globals *pg) /* {{{ */ memset(pg->io, 0, sizeof(pg->io)); pg->frame.num = 0; pg->sapi_name_ptr = NULL; - pg->socket_fd = -1; - pg->socket_server_fd = -1; pg->unclean_eval = 0; pg->req_id = 0; @@ -892,9 +889,6 @@ static void php_sapi_phpdbg_register_vars(zval *track_vars_array) /* {{{ */ static inline size_t php_sapi_phpdbg_ub_write(const char *message, size_t length) /* {{{ */ { - if (PHPDBG_G(socket_fd) != -1 && !(PHPDBG_G(flags) & PHPDBG_IS_INTERACTIVE)) { - send(PHPDBG_G(socket_fd), message, length, 0); - } return phpdbg_script(P_STDOUT, "%.*s", (int) length, message); } /* }}} */ diff --git a/sapi/phpdbg/phpdbg.h b/sapi/phpdbg/phpdbg.h index fa80e903e8c..1a4948c128a 100644 --- a/sapi/phpdbg/phpdbg.h +++ b/sapi/phpdbg/phpdbg.h @@ -318,10 +318,7 @@ ZEND_BEGIN_MODULE_GLOBALS(phpdbg) uint64_t flags; /* phpdbg flags */ - char *socket_path; /* phpdbg.path ini setting */ char *sapi_name_ptr; /* store sapi name to free it if necessary to not leak memory */ - int socket_fd; /* file descriptor to socket (wait command) (-1 if unused) */ - int socket_server_fd; /* file descriptor to master socket (wait command) (-1 if unused) */ #ifdef PHP_WIN32 HANDLE sigio_watcher_thread; /* sigio watcher thread handle */ struct win32_sigio_watcher_data swd; diff --git a/sapi/phpdbg/phpdbg_prompt.c b/sapi/phpdbg/phpdbg_prompt.c index 59f31853418..c16c9a82260 100644 --- a/sapi/phpdbg/phpdbg_prompt.c +++ b/sapi/phpdbg/phpdbg_prompt.c @@ -41,7 +41,6 @@ #include "phpdbg_frame.h" #include "phpdbg_lexer.h" #include "phpdbg_parser.h" -#include "phpdbg_wait.h" #include "phpdbg_eol.h" #if ZEND_VM_KIND != ZEND_VM_KIND_CALL && ZEND_VM_KIND != ZEND_VM_KIND_HYBRID @@ -89,7 +88,6 @@ const phpdbg_command_t phpdbg_prompt_commands[] = { PHPDBG_COMMAND_D(export, "export breaks to a .phpdbginit script", '>', NULL, "s", PHPDBG_ASYNC_SAFE), PHPDBG_COMMAND_D(sh, "shell a command", 0 , NULL, "i", 0), PHPDBG_COMMAND_D(quit, "exit phpdbg", 'q', NULL, 0, PHPDBG_ASYNC_SAFE), - PHPDBG_COMMAND_D(wait, "wait for other process", 'W', NULL, 0, 0), PHPDBG_COMMAND_D(watch, "set watchpoint", 'w', phpdbg_watch_commands, "|ss", 0), PHPDBG_COMMAND_D(next, "step over next line", 'n', NULL, 0, PHPDBG_ASYNC_SAFE), PHPDBG_COMMAND_D(eol, "set EOL", 'E', NULL, "|s", 0), @@ -897,11 +895,6 @@ free_cmd: } } zend_end_try(); - if (PHPDBG_G(socket_fd) != -1) { - close(PHPDBG_G(socket_fd)); - PHPDBG_G(socket_fd) = -1; - } - if (restore) { zend_exception_restore(); zend_try { diff --git a/sapi/phpdbg/phpdbg_prompt.h b/sapi/phpdbg/phpdbg_prompt.h index 21141fd79e9..b7b5df687d2 100644 --- a/sapi/phpdbg/phpdbg_prompt.h +++ b/sapi/phpdbg/phpdbg_prompt.h @@ -58,8 +58,7 @@ PHPDBG_COMMAND(register); PHPDBG_COMMAND(quit); PHPDBG_COMMAND(watch); PHPDBG_COMMAND(next); -PHPDBG_COMMAND(eol); -PHPDBG_COMMAND(wait); /* }}} */ +PHPDBG_COMMAND(eol); /* }}} */ /* {{{ prompt commands */ extern const phpdbg_command_t phpdbg_prompt_commands[]; /* }}} */ diff --git a/sapi/phpdbg/phpdbg_rinit_hook.c b/sapi/phpdbg/phpdbg_rinit_hook.c deleted file mode 100644 index 49fb0d39331..00000000000 --- a/sapi/phpdbg/phpdbg_rinit_hook.c +++ /dev/null @@ -1,107 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | Copyright (c) The PHP Group | - +----------------------------------------------------------------------+ - | This source file is subject to version 3.01 of the PHP license, | - | that is bundled with this package in the file LICENSE, and is | - | available through the world-wide-web at the following url: | - | https://www.php.net/license/3_01.txt | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Authors: Bob Weinand | - +----------------------------------------------------------------------+ -*/ - -#include "phpdbg_rinit_hook.h" -#include "php_ini.h" -#include - -ZEND_DECLARE_MODULE_GLOBALS(phpdbg_webhelper) - -PHP_INI_BEGIN() - STD_PHP_INI_ENTRY("phpdbg.auth", "", PHP_INI_SYSTEM | PHP_INI_PERDIR, OnUpdateString, auth, zend_phpdbg_webhelper_globals, phpdbg_webhelper_globals) - STD_PHP_INI_ENTRY("phpdbg.path", "", PHP_INI_SYSTEM | PHP_INI_PERDIR, OnUpdateString, path, zend_phpdbg_webhelper_globals, phpdbg_webhelper_globals) -PHP_INI_END() - -static inline void php_phpdbg_webhelper_globals_ctor(zend_phpdbg_webhelper_globals *pg) /* {{{ */ -{ -} /* }}} */ - -static PHP_MINIT_FUNCTION(phpdbg_webhelper) /* {{{ */ -{ - if (!strcmp(sapi_module.name, PHPDBG_NAME)) { - return SUCCESS; - } - - ZEND_INIT_MODULE_GLOBALS(phpdbg_webhelper, php_phpdbg_webhelper_globals_ctor, NULL); - REGISTER_INI_ENTRIES(); - - return SUCCESS; -} /* }}} */ - -static PHP_RINIT_FUNCTION(phpdbg_webhelper) /* {{{ */ -{ - zval cookies = PG(http_globals)[TRACK_VARS_COOKIE]; - zval *auth; - - if (Z_TYPE(cookies) == IS_ARRAY || (auth = zend_hash_str_find(Z_ARRVAL(cookies), PHPDBG_NAME "_AUTH_COOKIE", sizeof(PHPDBG_NAME "_AUTH_COOKIE"))) || Z_STRLEN_P(auth) != strlen(PHPDBG_WG(auth)) || strcmp(Z_STRVAL_P(auth), PHPDBG_WG(auth))) { - return SUCCESS; - } - -#ifndef _WIN32 - { - struct sockaddr_un sock; - int s = socket(AF_UNIX, SOCK_STREAM, 0); - size_t len = strlen(PHPDBG_WG(path)) + sizeof(sock.sun_family); - char buf[(1 << 8) + 1]; - ssize_t buflen; - sock.sun_family = AF_UNIX; - strcpy(sock.sun_path, PHPDBG_WG(path)); - - if (connect(s, (struct sockaddr *)&sock, len) == -1) { - zend_error(E_ERROR, "Unable to connect to UNIX domain socket at %s defined by phpdbg.path ini setting. Reason: %s", PHPDBG_WG(path), strerror(errno)); - } - - char *msg = NULL; - size_t msglen = 0; - phpdbg_webdata_compress(&msg, &msglen); - - buf[0] = (msglen >> 0) & 0xff; - buf[1] = (msglen >> 8) & 0xff; - buf[2] = (msglen >> 16) & 0xff; - buf[3] = (msglen >> 24) & 0xff; - send(s, buf, 4, 0); - send(s, msg, msglen, 0); - - while ((buflen = recv(s, buf, sizeof(buf) - 1, 0)) > 0) { - php_write(buf, buflen); - } - - close(s); - - php_output_flush_all(); - zend_bailout(); - } -#endif - - return SUCCESS; -} /* }}} */ - -zend_module_entry phpdbg_webhelper_module_entry = { - STANDARD_MODULE_HEADER, - "phpdbg_webhelper", - NULL, - PHP_MINIT(phpdbg_webhelper), - NULL, - PHP_RINIT(phpdbg_webhelper), - NULL, - NULL, - PHPDBG_VERSION, - STANDARD_MODULE_PROPERTIES -}; - -#ifdef COMPILE_DL_PHPDBG_WEBHELPER -ZEND_GET_MODULE(phpdbg_webhelper) -#endif diff --git a/sapi/phpdbg/phpdbg_rinit_hook.h b/sapi/phpdbg/phpdbg_rinit_hook.h deleted file mode 100644 index 010eaf9ed76..00000000000 --- a/sapi/phpdbg/phpdbg_rinit_hook.h +++ /dev/null @@ -1,39 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | Copyright (c) The PHP Group | - +----------------------------------------------------------------------+ - | This source file is subject to version 3.01 of the PHP license, | - | that is bundled with this package in the file LICENSE, and is | - | available through the world-wide-web at the following url: | - | https://www.php.net/license/3_01.txt | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Authors: Felipe Pena | - | Authors: Joe Watkins | - | Authors: Bob Weinand | - +----------------------------------------------------------------------+ -*/ - -#ifndef PHPDBG_WEBHELPER_H -#define PHPDBG_WEBHELPER_H - -#include "phpdbg_webdata_transfer.h" - -extern zend_module_entry phpdbg_webhelper_module_entry; -#define phpext_phpdbg_webhelper_ptr &phpdbg_webhelper_module_entry - -#ifdef ZTS -# define PHPDBG_WG(v) ZEND_TSRMG(phpdbg_webhelper_globals_id, zend_phpdbg_webhelper_globals *, v) -#else -# define PHPDBG_WG(v) (phpdbg_webhelper_globals.v) -#endif - -/* {{{ structs */ -ZEND_BEGIN_MODULE_GLOBALS(phpdbg_webhelper) - char *auth; - char *path; -ZEND_END_MODULE_GLOBALS(phpdbg_webhelper) /* }}} */ - -#endif /* PHPDBG_WEBHELPER_H */ diff --git a/sapi/phpdbg/phpdbg_wait.c b/sapi/phpdbg/phpdbg_wait.c deleted file mode 100644 index 407f7cb8940..00000000000 --- a/sapi/phpdbg/phpdbg_wait.c +++ /dev/null @@ -1,407 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | Copyright (c) The PHP Group | - +----------------------------------------------------------------------+ - | This source file is subject to version 3.01 of the PHP license, | - | that is bundled with this package in the file LICENSE, and is | - | available through the world-wide-web at the following url: | - | https://www.php.net/license/3_01.txt | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Authors: Bob Weinand | - +----------------------------------------------------------------------+ -*/ - -#include "phpdbg_wait.h" -#include "phpdbg_prompt.h" -#include "ext/standard/php_var.h" -#include "ext/standard/basic_functions.h" - -ZEND_EXTERN_MODULE_GLOBALS(phpdbg) - -static void phpdbg_rebuild_http_globals_array(int type, const char *name) { - zval *zvp; - if (Z_TYPE(PG(http_globals)[type]) != IS_UNDEF) { - zval_ptr_dtor_nogc(&PG(http_globals)[type]); - } - if ((zvp = zend_hash_str_find(&EG(symbol_table), name, strlen(name)))) { - Z_ADDREF_P(zvp); - PG(http_globals)[type] = *zvp; - } -} - - -static int phpdbg_dearm_autoglobals(zend_auto_global *auto_global) { - if (zend_string_equals_literal(auto_global->name, "GLOBALS")) { - auto_global->armed = 0; - } - - return ZEND_HASH_APPLY_KEEP; -} - -typedef struct { - HashTable *ht[2]; - HashPosition pos[2]; -} phpdbg_intersect_ptr; - -static int phpdbg_array_data_compare(Bucket *f, Bucket *s) { - int result; - zval *first, *second; - - first = &f->val; - second = &s->val; - - result = string_compare_function(first, second); - - if (result < 0) { - return -1; - } else if (result > 0) { - return 1; - } - - return 0; -} - -static void phpdbg_array_intersect_init(phpdbg_intersect_ptr *info, HashTable *ht1, HashTable *ht2) { - info->ht[0] = ht1; - info->ht[1] = ht2; - - zend_hash_sort(info->ht[0], phpdbg_array_data_compare, 0); - zend_hash_sort(info->ht[1], phpdbg_array_data_compare, 0); - - zend_hash_internal_pointer_reset_ex(info->ht[0], &info->pos[0]); - zend_hash_internal_pointer_reset_ex(info->ht[1], &info->pos[1]); -} - -/* -1 => first array, 0 => both arrays equal, 1 => second array */ -static int phpdbg_array_intersect(phpdbg_intersect_ptr *info, zval **ptr) { - int ret; - zval *zvp[2]; - int invalid = !info->ht[0] + !info->ht[1]; - - if (invalid > 0) { - invalid = !info->ht[0]; - - if (!(*ptr = zend_hash_get_current_data_ex(info->ht[invalid], &info->pos[invalid]))) { - return 0; - } - - zend_hash_move_forward_ex(info->ht[invalid], &info->pos[invalid]); - - return invalid ? 1 : -1; - } - - if (!(zvp[0] = zend_hash_get_current_data_ex(info->ht[0], &info->pos[0]))) { - info->ht[0] = NULL; - return phpdbg_array_intersect(info, ptr); - } - if (!(zvp[1] = zend_hash_get_current_data_ex(info->ht[1], &info->pos[1]))) { - info->ht[1] = NULL; - return phpdbg_array_intersect(info, ptr); - } - - ret = zend_binary_zval_strcmp(zvp[0], zvp[1]); - - if (ret <= 0) { - *ptr = zvp[0]; - zend_hash_move_forward_ex(info->ht[0], &info->pos[0]); - } - if (ret >= 0) { - *ptr = zvp[1]; - zend_hash_move_forward_ex(info->ht[1], &info->pos[1]); - } - - return ret; -} - -void phpdbg_webdata_decompress(char *msg, int len) { - zval *free_zv = NULL; - zval zv, *zvp; - HashTable *ht; - php_unserialize_data_t var_hash; - - PHP_VAR_UNSERIALIZE_INIT(var_hash); - if (!php_var_unserialize(&zv, (const unsigned char **) &msg, (unsigned char *) msg + len, &var_hash)) { - PHP_VAR_UNSERIALIZE_DESTROY(var_hash); - phpdbg_error("wait", "type=\"invaliddata\" import=\"fail\"", "Malformed serialized was sent to this socket, aborting"); - return; - } - PHP_VAR_UNSERIALIZE_DESTROY(var_hash); - - ht = Z_ARRVAL(zv); - - /* Reapply symbol table */ - if ((zvp = zend_hash_str_find(ht, ZEND_STRL("GLOBALS"))) && Z_TYPE_P(zvp) == IS_ARRAY) { - { - zval *srv; - if ((srv = zend_hash_find(Z_ARRVAL_P(zvp), ZSTR_KNOWN(ZEND_STR_AUTOGLOBAL_SERVER))) && Z_TYPE_P(srv) == IS_ARRAY) { - zval *script; - if ((script = zend_hash_str_find(Z_ARRVAL_P(srv), ZEND_STRL("SCRIPT_FILENAME"))) && Z_TYPE_P(script) == IS_STRING) { - phpdbg_param_t param; - param.str = Z_STRVAL_P(script); - PHPDBG_COMMAND_HANDLER(exec)(¶m); - } - } - } - - PG(auto_globals_jit) = 0; - zend_hash_apply(CG(auto_globals), (apply_func_t) phpdbg_dearm_autoglobals); - - zend_hash_clean(&EG(symbol_table)); - EG(symbol_table) = *Z_ARR_P(zvp); - - /* Rebuild cookies, env vars etc. from GLOBALS (PG(http_globals)) */ - phpdbg_rebuild_http_globals_array(TRACK_VARS_POST, "_POST"); - phpdbg_rebuild_http_globals_array(TRACK_VARS_GET, "_GET"); - phpdbg_rebuild_http_globals_array(TRACK_VARS_COOKIE, "_COOKIE"); - phpdbg_rebuild_http_globals_array(TRACK_VARS_SERVER, "_SERVER"); - phpdbg_rebuild_http_globals_array(TRACK_VARS_ENV, "_ENV"); - phpdbg_rebuild_http_globals_array(TRACK_VARS_FILES, "_FILES"); - - Z_ADDREF_P(zvp); - free_zv = zvp; - } - - if ((zvp = zend_hash_str_find(ht, ZEND_STRL("input"))) && Z_TYPE_P(zvp) == IS_STRING) { - if (SG(request_info).request_body) { - php_stream_close(SG(request_info).request_body); - } - SG(request_info).request_body = php_stream_temp_create_ex(TEMP_STREAM_DEFAULT, SAPI_POST_BLOCK_SIZE, PG(upload_tmp_dir)); - php_stream_truncate_set_size(SG(request_info).request_body, 0); - php_stream_write(SG(request_info).request_body, Z_STRVAL_P(zvp), Z_STRLEN_P(zvp)); - } - - if ((zvp = zend_hash_str_find(ht, ZEND_STRL("cwd"))) && Z_TYPE_P(zvp) == IS_STRING) { - if (VCWD_CHDIR(Z_STRVAL_P(zvp)) == SUCCESS) { - if (BG(CurrentStatFile) && !IS_ABSOLUTE_PATH(ZSTR_VAL(BG(CurrentStatFile)), ZSTR_LEN(BG(CurrentStatFile)))) { - zend_string_release(BG(CurrentStatFile)); - BG(CurrentStatFile) = NULL; - } - if (BG(CurrentLStatFile) && !IS_ABSOLUTE_PATH(ZSTR_VAL(BG(CurrentLStatFile)), ZSTR_LEN(BG(CurrentLStatFile)))) { - zend_string_release(BG(CurrentLStatFile)); - BG(CurrentLStatFile) = NULL; - } - } - } - - if ((zvp = zend_hash_str_find(ht, ZEND_STRL("sapi_name"))) && (Z_TYPE_P(zvp) == IS_STRING || Z_TYPE_P(zvp) == IS_NULL)) { - if (PHPDBG_G(sapi_name_ptr)) { - free(PHPDBG_G(sapi_name_ptr)); - } - if (Z_TYPE_P(zvp) == IS_STRING) { - PHPDBG_G(sapi_name_ptr) = sapi_module.name = strdup(Z_STRVAL_P(zvp)); - } else { - PHPDBG_G(sapi_name_ptr) = sapi_module.name = NULL; - } - } - - if ((zvp = zend_hash_str_find(ht, ZEND_STRL("modules"))) && Z_TYPE_P(zvp) == IS_ARRAY) { - phpdbg_intersect_ptr pos; - zval *module; - zend_module_entry *mod; - HashTable zv_registry; - - /* intersect modules, unregister modules loaded "too much", announce not yet registered modules (phpdbg_notice) */ - - zend_hash_init(&zv_registry, zend_hash_num_elements(&module_registry), 0, ZVAL_PTR_DTOR, 0); - ZEND_HASH_FOREACH_PTR(&module_registry, mod) { - if (mod->name) { - zval value; - ZVAL_NEW_STR(&value, zend_string_init(mod->name, strlen(mod->name), 0)); - zend_hash_next_index_insert(&zv_registry, &value); - } - } ZEND_HASH_FOREACH_END(); - - phpdbg_array_intersect_init(&pos, &zv_registry, Z_ARRVAL_P(zvp)); - do { - int mode = phpdbg_array_intersect(&pos, &module); - if (mode < 0) { - // loaded module, but not needed - if (strcmp(PHPDBG_NAME, Z_STRVAL_P(module))) { - zend_hash_del(&module_registry, Z_STR_P(module)); - } - } else if (mode > 0) { - // not loaded module - if (!sapi_module.name || strcmp(sapi_module.name, Z_STRVAL_P(module))) { - phpdbg_notice("wait", "missingmodule=\"%.*s\"", "The module %.*s isn't present in " PHPDBG_NAME ", you still can load via dl /path/to/module/%.*s.so", (int) Z_STRLEN_P(module), Z_STRVAL_P(module), (int) Z_STRLEN_P(module), Z_STRVAL_P(module)); - } - } - } while (module); - - zend_hash_clean(&zv_registry); - } - - if ((zvp = zend_hash_str_find(ht, ZEND_STRL("extensions"))) && Z_TYPE_P(zvp) == IS_ARRAY) { - zend_extension *extension; - zend_llist_position pos; - zval *name = NULL; - zend_string *strkey = NULL; - - extension = (zend_extension *) zend_llist_get_first_ex(&zend_extensions, &pos); - while (extension) { - extension = (zend_extension *) zend_llist_get_next_ex(&zend_extensions, &pos); - if (extension == NULL){ - break; - } - - ZEND_HASH_FOREACH_STR_KEY_PTR(Z_ARRVAL_P(zvp), strkey, name) { - if (Z_TYPE_P(name) == IS_STRING && !zend_binary_strcmp(extension->name, strlen(extension->name), Z_STRVAL_P(name), Z_STRLEN_P(name))) { - break; - } - name = NULL; - strkey = NULL; - } ZEND_HASH_FOREACH_END(); - - if (name) { - /* sigh, breaking the encapsulation, there aren't any functions manipulating the llist at the place of the zend_llist_position */ - zend_llist_element *elm = pos; - if (elm->prev) { - elm->prev->next = elm->next; - } else { - zend_extensions.head = elm->next; - } - if (elm->next) { - elm->next->prev = elm->prev; - } else { - zend_extensions.tail = elm->prev; - } -#if ZEND_EXTENSIONS_SUPPORT - if (extension->shutdown) { - extension->shutdown(extension); - } -#endif - if (zend_extensions.dtor) { - zend_extensions.dtor(elm->data); - } - pefree(elm, zend_extensions.persistent); - zend_extensions.count--; - } else { - ZEND_ASSERT(strkey); - zend_hash_del(Z_ARRVAL_P(zvp), strkey); - } - } - - ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(zvp), name) { - if (Z_TYPE_P(name) == IS_STRING) { - phpdbg_notice("wait", "missingextension=\"%.*s\"", "The Zend extension %.*s isn't present in " PHPDBG_NAME ", you still can load via dl /path/to/extension.so", (int) Z_STRLEN_P(name), Z_STRVAL_P(name)); - } - } ZEND_HASH_FOREACH_END(); - } - - zend_ini_deactivate(); - - if ((zvp = zend_hash_str_find(ht, ZEND_STRL("systemini"))) && Z_TYPE_P(zvp) == IS_ARRAY) { - zval *ini_entry; - zend_ini_entry *original_ini; - zend_string *key; - - ZEND_HASH_FOREACH_STR_KEY_VAL(Z_ARRVAL_P(zvp), key, ini_entry) { - if (key && Z_TYPE_P(ini_entry) == IS_STRING) { - if ((original_ini = zend_hash_find_ptr(EG(ini_directives), key))) { - if (!original_ini->on_modify || original_ini->on_modify(original_ini, Z_STR_P(ini_entry), original_ini->mh_arg1, original_ini->mh_arg2, original_ini->mh_arg3, ZEND_INI_STAGE_ACTIVATE) == SUCCESS) { - if (original_ini->modified && original_ini->orig_value != original_ini->value) { - efree(original_ini->value); - } - original_ini->value = Z_STR_P(ini_entry); - Z_ADDREF_P(ini_entry); /* don't free the string */ - } - } - } - } ZEND_HASH_FOREACH_END(); - } - - if ((zvp = zend_hash_str_find(ht, ZEND_STRL("userini"))) && Z_TYPE_P(zvp) == IS_ARRAY) { - zval *ini_entry; - zend_string *key; - - ZEND_HASH_FOREACH_STR_KEY_VAL(Z_ARRVAL_P(zvp), key, ini_entry) { - if (key && Z_TYPE_P(ini_entry) == IS_STRING) { - zend_alter_ini_entry_ex(key, Z_STR_P(ini_entry), ZEND_INI_PERDIR, ZEND_INI_STAGE_HTACCESS, 1); - } - } ZEND_HASH_FOREACH_END(); - } - - zval_ptr_dtor(&zv); - if (free_zv) { - /* separate freeing to not dtor the symtable too, just the container zval... */ - efree(free_zv); - } - - /* Reapply raw input */ - /* ??? */ -} - -PHPDBG_COMMAND(wait) /* {{{ */ -{ -#ifndef PHP_WIN32 - struct sockaddr_un local, remote; - int rlen, sr, sl; - unlink(PHPDBG_G(socket_path)); - if (PHPDBG_G(socket_server_fd) == -1) { - int len; - PHPDBG_G(socket_server_fd) = sl = socket(AF_UNIX, SOCK_STREAM, 0); - if (sl == -1) { - phpdbg_error("wait", "type=\"nosocket\" import=\"fail\"", "Unable to open a socket to UNIX domain socket at %s defined by phpdbg.path ini setting", PHPDBG_G(socket_path)); - return FAILURE; - } - - local.sun_family = AF_UNIX; - if (strlcpy(local.sun_path, PHPDBG_G(socket_path), sizeof(local.sun_path)) > sizeof(local.sun_path)) { - phpdbg_error("wait", "type=\"nosocket\" import=\"fail\"", "Socket at %s defined by phpdbg.path ini setting is too long", PHPDBG_G(socket_path)); - return FAILURE; - } - len = strlen(local.sun_path) + sizeof(local.sun_family); - if (bind(sl, (struct sockaddr *)&local, len) == -1) { - phpdbg_error("wait", "type=\"nosocket\" import=\"fail\"", "Unable to connect to UNIX domain socket at %s defined by phpdbg.path ini setting", PHPDBG_G(socket_path)); - return FAILURE; - } - - chmod(PHPDBG_G(socket_path), 0666); - - listen(sl, 2); - } else { - sl = PHPDBG_G(socket_server_fd); - } - - rlen = sizeof(remote); - sr = accept(sl, (struct sockaddr *) &remote, (socklen_t *) &rlen); - if (sr == -1) { - phpdbg_error("wait", "type=\"nosocket\" import=\"fail\"", "Unable to create a connection to UNIX domain socket at %s defined by phpdbg.path ini setting", PHPDBG_G(socket_path)); - close(PHPDBG_G(socket_server_fd)); - return FAILURE; - } - - unsigned char msglen_buf[4]; - int needed = 4; - - do { - needed -= recv(sr, &msglen_buf[4 - needed], needed, 0); - } while (needed > 0); - - uint32_t msglen = (msglen_buf[3] << 24) - | (msglen_buf[2] << 16) - | (msglen_buf[1] << 8) - | (msglen_buf[0] << 0); - char *data = emalloc(msglen); - needed = msglen; - - do { - needed -= recv(sr, &(data[msglen - needed]), needed, 0); - } while (needed > 0); - - phpdbg_webdata_decompress(data, msglen); - - if (PHPDBG_G(socket_fd) != -1) { - close(PHPDBG_G(socket_fd)); - } - PHPDBG_G(socket_fd) = sr; - - efree(data); - - phpdbg_notice("wait", "import=\"success\"", "Successfully imported request data, stopped before executing"); -#endif - - return SUCCESS; -} /* }}} */ diff --git a/sapi/phpdbg/phpdbg_wait.h b/sapi/phpdbg/phpdbg_wait.h deleted file mode 100644 index 5e5a15edf7b..00000000000 --- a/sapi/phpdbg/phpdbg_wait.h +++ /dev/null @@ -1,27 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | Copyright (c) The PHP Group | - +----------------------------------------------------------------------+ - | This source file is subject to version 3.01 of the PHP license, | - | that is bundled with this package in the file LICENSE, and is | - | available through the world-wide-web at the following url: | - | https://www.php.net/license/3_01.txt | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Authors: Bob Weinand | - +----------------------------------------------------------------------+ -*/ - -#ifndef PHPDBG_WAIT_H -#define PHPDBG_WAIT_H - -#include "zend.h" -#include "phpdbg.h" - -PHPDBG_COMMAND(wait); - -void phpdbg_webdata_decompress(char *msg, int len); - -#endif /* PHPDBG_WAIT_H */ diff --git a/sapi/phpdbg/phpdbg_webdata_transfer.c b/sapi/phpdbg/phpdbg_webdata_transfer.c deleted file mode 100644 index 0783fbdb109..00000000000 --- a/sapi/phpdbg/phpdbg_webdata_transfer.c +++ /dev/null @@ -1,164 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | Copyright (c) The PHP Group | - +----------------------------------------------------------------------+ - | This source file is subject to version 3.01 of the PHP license, | - | that is bundled with this package in the file LICENSE, and is | - | available through the world-wide-web at the following url: | - | https://www.php.net/license/3_01.txt | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Authors: Bob Weinand | - +----------------------------------------------------------------------+ -*/ - -#include "phpdbg_webdata_transfer.h" -#include "ext/standard/php_var.h" - -PHPDBG_API void phpdbg_webdata_compress(char **msg, size_t *len) { - zval array; - HashTable *ht; - zval zv[9]; - - array_init(&array); - ht = Z_ARRVAL(array); - - /* fetch superglobals */ - { - /* might be JIT */ - zend_is_auto_global(ZSTR_KNOWN(ZEND_STR_AUTOGLOBAL_ENV)); - zend_is_auto_global(ZSTR_KNOWN(ZEND_STR_AUTOGLOBAL_SERVER)); - zend_is_auto_global(ZSTR_KNOWN(ZEND_STR_AUTOGLOBAL_REQUEST)); - array_init(&zv[1]); - zend_hash_copy(Z_ARRVAL(zv[1]), &EG(symbol_table), NULL); - Z_ARRVAL(zv[1])->pDestructor = NULL; /* we're operating on a copy! Don't double free zvals */ - zend_hash_str_del(Z_ARRVAL(zv[1]), ZEND_STRL("GLOBALS")); /* do not use the reference to itself in json */ - zend_hash_str_add(ht, ZEND_STRL("GLOBALS"), &zv[1]); - } - - /* save php://input */ - { - php_stream *stream; - zend_string *str; - - stream = php_stream_temp_create_ex(TEMP_STREAM_DEFAULT, SAPI_POST_BLOCK_SIZE, PG(upload_tmp_dir)); - if ((str = php_stream_copy_to_mem(stream, PHP_STREAM_COPY_ALL, 0))) { - ZVAL_STR(&zv[2], str); - } else { - ZVAL_EMPTY_STRING(&zv[2]); - } - Z_SET_REFCOUNT(zv[2], 1); - zend_hash_str_add(ht, ZEND_STRL("input"), &zv[2]); - } - - /* change sapi name */ - { - if (sapi_module.name) { - ZVAL_STRING(&zv[6], sapi_module.name); - } else { - Z_TYPE_INFO(zv[6]) = IS_NULL; - } - zend_hash_str_add(ht, ZEND_STRL("sapi_name"), &zv[6]); - Z_SET_REFCOUNT(zv[6], 1); - } - - /* handle modules / extensions */ - { - zend_module_entry *module; - zend_extension *extension; - zend_llist_position pos; - - array_init(&zv[7]); - ZEND_HASH_FOREACH_PTR(&module_registry, module) { - zval *value = ecalloc(sizeof(zval), 1); - ZVAL_STRING(value, module->name); - zend_hash_next_index_insert(Z_ARRVAL(zv[7]), value); - } ZEND_HASH_FOREACH_END(); - zend_hash_str_add(ht, ZEND_STRL("modules"), &zv[7]); - - array_init(&zv[8]); - extension = (zend_extension *) zend_llist_get_first_ex(&zend_extensions, &pos); - while (extension) { - zval *value = ecalloc(sizeof(zval), 1); - ZVAL_STRING(value, extension->name); - zend_hash_next_index_insert(Z_ARRVAL(zv[8]), value); - extension = (zend_extension *) zend_llist_get_next_ex(&zend_extensions, &pos); - } - zend_hash_str_add(ht, ZEND_STRL("extensions"), &zv[8]); - } - - /* switch cwd */ - if (SG(options) & SAPI_OPTION_NO_CHDIR) { - char *ret = NULL; - char path[MAXPATHLEN]; - -#if HAVE_GETCWD - ret = VCWD_GETCWD(path, MAXPATHLEN); -#elif HAVE_GETWD - ret = VCWD_GETWD(path); -#endif - if (ret) { - ZVAL_STRING(&zv[5], path); - Z_SET_REFCOUNT(zv[5], 1); - zend_hash_str_add(ht, ZEND_STRL("cwd"), &zv[5]); - } - } - - /* get system ini entries */ - { - zend_ini_entry *ini_entry; - - array_init(&zv[3]); - ZEND_HASH_FOREACH_PTR(EG(ini_directives), ini_entry) { - zval *value = ecalloc(sizeof(zval), 1); - if (ini_entry->modified) { - if (!ini_entry->orig_value) { - efree(value); - continue; - } - ZVAL_STR(value, ini_entry->orig_value); - } else { - if (!ini_entry->value) { - efree(value); - continue; - } - ZVAL_STR(value, ini_entry->value); - } - zend_hash_add(Z_ARRVAL(zv[3]), ini_entry->name, value); - } ZEND_HASH_FOREACH_END(); - zend_hash_str_add(ht, ZEND_STRL("systemini"), &zv[3]); - } - - /* get perdir ini entries */ - if (EG(modified_ini_directives)) { - zend_ini_entry *ini_entry; - - array_init(&zv[4]); - ZEND_HASH_FOREACH_PTR(EG(ini_directives), ini_entry) { - zval *value = ecalloc(sizeof(zval), 1); - if (!ini_entry->value) { - efree(value); - continue; - } - ZVAL_STR(value, ini_entry->value); - zend_hash_add(Z_ARRVAL(zv[4]), ini_entry->name, value); - } ZEND_HASH_FOREACH_END(); - zend_hash_str_add(ht, ZEND_STRL("userini"), &zv[4]); - } - - /* encode data */ - { - php_serialize_data_t var_hash; - smart_str buf = {0}; - - PHP_VAR_SERIALIZE_INIT(var_hash); - php_var_serialize(&buf, &array, &var_hash); - PHP_VAR_SERIALIZE_DESTROY(var_hash); - *msg = ZSTR_VAL(buf.s); - *len = ZSTR_LEN(buf.s); - } - - zend_array_destroy(Z_ARR(array)); -} diff --git a/sapi/phpdbg/phpdbg_webdata_transfer.h b/sapi/phpdbg/phpdbg_webdata_transfer.h deleted file mode 100644 index d22c208ebaa..00000000000 --- a/sapi/phpdbg/phpdbg_webdata_transfer.h +++ /dev/null @@ -1,25 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | Copyright (c) The PHP Group | - +----------------------------------------------------------------------+ - | This source file is subject to version 3.01 of the PHP license, | - | that is bundled with this package in the file LICENSE, and is | - | available through the world-wide-web at the following url: | - | https://www.php.net/license/3_01.txt | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Authors: Bob Weinand | - +----------------------------------------------------------------------+ -*/ - -#ifndef PHPDBG_WEBDATA_TRANSFER_H -#define PHPDBG_WEBDATA_TRANSFER_H - -#include "zend.h" -#include "phpdbg.h" - -PHPDBG_API void phpdbg_webdata_compress(char **msg, size_t *len); - -#endif /* PHPDBG_WEBDATA_TRANSFER_H */ diff --git a/sapi/phpdbg/xml.md b/sapi/phpdbg/xml.md index bd99b0d3f5b..42c71465178 100644 --- a/sapi/phpdbg/xml.md +++ b/sapi/phpdbg/xml.md @@ -568,21 +568,6 @@ set - generally enables / disables showing of refcount in watchpoint breaks silently with no further xml answer - if the boolean switch is omitted, it emits current state in a <setrefcount active="" /> where active is on or off -wait ----- - -- internally executes exec, so exec will output first (if binding to socket worked) - -### attributes ### - -- import: has value "success"/"fail" -- missingmodule/missingextension: modules/extensions loaded in the target SAPI, but not in phpdbg - -### errors (by type) ### - -- nosocket: couldn't establish socket -- invaliddata: invalid JSON passed to socket - dl --