From 12067d71aaf849b13bc211cd81507d65d9d0cbbe Mon Sep 17 00:00:00 2001 From: Dmitrijs Goloscapovs Date: Wed, 11 Oct 2023 08:01:06 -0400 Subject: [PATCH] fixed crash in manual script execution --- src/libs/zbxscripts/scripts.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/libs/zbxscripts/scripts.c b/src/libs/zbxscripts/scripts.c index 5756c4db2e8..b1c39010fae 100644 --- a/src/libs/zbxscripts/scripts.c +++ b/src/libs/zbxscripts/scripts.c @@ -425,7 +425,7 @@ out: } static int passive_command_send_and_result_fetch(const zbx_dc_host_t *host, const char *command, char **result, - const char *config_source_ip, char *error, size_t max_error_len) + int config_timeout, const char *config_source_ip, char *error, size_t max_error_len) { int ret; AGENT_RESULT agent_result; @@ -463,6 +463,7 @@ static int passive_command_send_and_result_fetch(const zbx_dc_host_t *host, cons item.key = zbx_dsprintf(item.key, "system.run[%s%s]", param, NULL == result ? ",nowait" : ""); item.value_type = ITEM_VALUE_TYPE_TEXT; + item.timeout = zbx_dsprintf(item.timeout, "%ds", config_timeout); zbx_init_agent_result(&agent_result); @@ -478,6 +479,7 @@ static int passive_command_send_and_result_fetch(const zbx_dc_host_t *host, cons zbx_free_agent_result(&agent_result); zbx_free(item.key); + zbx_free(item.timeout); fail: zbx_free(port); zbx_free(param); @@ -502,12 +504,12 @@ static int zbx_execute_script_on_agent(const zbx_dc_host_t *host, const char *co error, max_error_len); } - return passive_command_send_and_result_fetch(host, command, result, config_source_ip, error, + return passive_command_send_and_result_fetch(host, command, result, config_timeout, config_source_ip, error, max_error_len); } static int zbx_execute_script_on_terminal(const zbx_dc_host_t *host, const zbx_script_t *script, char **result, - const char *config_source_ip, char *error, size_t max_error_len) + int config_timeout, const char *config_source_ip, char *error, size_t max_error_len) { int ret = FAIL; AGENT_RESULT agent_result; @@ -570,6 +572,7 @@ static int zbx_execute_script_on_terminal(const zbx_dc_host_t *host, const zbx_s #endif item.value_type = ITEM_VALUE_TYPE_TEXT; item.params = zbx_strdup(item.params, script->command); + item.timeout = zbx_dsprintf(item.timeout, "%ds", config_timeout); zbx_init_agent_result(&agent_result); @@ -586,6 +589,7 @@ static int zbx_execute_script_on_terminal(const zbx_dc_host_t *host, const zbx_s zbx_free(item.params); zbx_free(item.key); + zbx_free(item.timeout); fail: zabbix_log(LOG_LEVEL_DEBUG, "End of %s():%s", __func__, zbx_result_string(ret)); @@ -905,7 +909,7 @@ int zbx_script_execute(const zbx_script_t *script, const zbx_dc_host_t *host, co break; #endif case ZBX_SCRIPT_TYPE_TELNET: - ret = zbx_execute_script_on_terminal(host, script, result, config_source_ip, + ret = zbx_execute_script_on_terminal(host, script, result, config_timeout, config_source_ip, error, max_error_len); break; default: -- 2.30.2