diff options
Diffstat (limited to 'src/libs/zbxembed/zabbix.c')
-rw-r--r-- | src/libs/zbxembed/zabbix.c | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/src/libs/zbxembed/zabbix.c b/src/libs/zbxembed/zabbix.c index 61a6ba302d9..ee487552df6 100644 --- a/src/libs/zbxembed/zabbix.c +++ b/src/libs/zbxembed/zabbix.c @@ -69,12 +69,17 @@ static duk_ret_t es_zabbix_ctor(duk_context *ctx) static duk_ret_t es_zabbix_log(duk_context *ctx) { zbx_es_env_t *env; - const char *message; + char *message = NULL; int level; duk_memory_functions out_funcs; level = duk_to_int(ctx, 0); - message = duk_to_string(ctx, 1); + + if (SUCCEED != zbx_cesu8_to_utf8(duk_to_string(ctx, 1), &message)) + { + message = zbx_strdup(message, duk_to_string(ctx, 1)); + zbx_replace_invalid_utf8(message); + } zabbix_log(level, "%s", message); @@ -82,7 +87,10 @@ static duk_ret_t es_zabbix_log(duk_context *ctx) env = (zbx_es_env_t *)out_funcs.udata; if (NULL == env->json) + { + zbx_free(message); return 0; + } zbx_json_addobject(env->json, NULL); zbx_json_adduint64(env->json, "level", (zbx_uint64_t)level); @@ -90,6 +98,8 @@ static duk_ret_t es_zabbix_log(duk_context *ctx) zbx_json_addstring(env->json, "message", message, ZBX_JSON_TYPE_STRING); zbx_json_close(env->json); + 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.", |