Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/zabbix/zabbix.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndris Zeila <andris.zeila@zabbix.com>2020-06-26 09:44:41 +0300
committerAndris Zeila <andris.zeila@zabbix.com>2020-06-26 09:44:59 +0300
commitc5ce5256a3d9f9361b122407f51e2bacf27e4ca7 (patch)
tree07507e74a664799ca9d080447e681265f10c501b /src/libs/zbxembed/zabbix.c
parent454ed551c43c8695a3213f63b1984908f069861c (diff)
.......PS. [ZBX-17837] fixed memory leaks when handling CurlHttpRequest errors
* commit '7c735c2d13a8da7f149295b0de67fcffaebf7e5d': .D........ [ZBX-17837] added changelog entry .......PS. [ZBX-17837] moved check for Zabbix.Log json buffer limits before adding log to the buffer. Otherwise it would be possible to exceed the limits if user would handle exception generated by Zabbix.Log() limits. .......PS. [ZBX-17837] fixed error handling in CurlHttpRequest implementation .......... [ZBX-17837] reset error message after embeded scripting api call failure .......PS. [ZBX-17837] fixed memory leaks if ZBX_CURL_SETOPT() fails .......PS. [ZBX-17837] modified macro ZBX_CURL_SETOPT() to avoid throwing duk_error() (cherry picked from commit a807da8fdeff9d2edd851f942c84fdb7c811e813)
Diffstat (limited to 'src/libs/zbxembed/zabbix.c')
-rw-r--r--src/libs/zbxembed/zabbix.c19
1 files changed, 10 insertions, 9 deletions
diff --git a/src/libs/zbxembed/zabbix.c b/src/libs/zbxembed/zabbix.c
index ee487552df6..7b7bc8d1094 100644
--- a/src/libs/zbxembed/zabbix.c
+++ b/src/libs/zbxembed/zabbix.c
@@ -70,7 +70,7 @@ static duk_ret_t es_zabbix_log(duk_context *ctx)
{
zbx_es_env_t *env;
char *message = NULL;
- int level;
+ int level, err_index = -1;
duk_memory_functions out_funcs;
level = duk_to_int(ctx, 0);
@@ -87,9 +87,13 @@ static duk_ret_t es_zabbix_log(duk_context *ctx)
env = (zbx_es_env_t *)out_funcs.udata;
if (NULL == env->json)
+ goto out;
+
+ if (ZBX_ES_LOG_MEMORY_LIMIT < env->json->buffer_size) /* approximate limit */
{
- zbx_free(message);
- return 0;
+ err_index = duk_push_error_object(ctx, DUK_RET_EVAL_ERROR, "log exceeds the maximum size of "
+ ZBX_FS_UI64 " bytes.", ZBX_ES_LOG_MEMORY_LIMIT);
+ goto out;
}
zbx_json_addobject(env->json, NULL);
@@ -97,14 +101,11 @@ static duk_ret_t es_zabbix_log(duk_context *ctx)
zbx_json_adduint64(env->json, "ms", zbx_get_duration_ms(&env->start_time));
zbx_json_addstring(env->json, "message", message, ZBX_JSON_TYPE_STRING);
zbx_json_close(env->json);
-
+out:
zbx_free(message);
- if (ZBX_ES_LOG_MEMORY_LIMIT < env->json->buffer_size) /* approximate limit */
- {
- return duk_error(ctx, DUK_RET_TYPE_ERROR, "log exceeds the maximum size of " ZBX_FS_UI64 " bytes.",
- ZBX_ES_LOG_MEMORY_LIMIT);
- }
+ if (-1 != err_index)
+ return duk_throw(ctx);
return 0;
}