From 4d7833a1abf0612d06830f098e57688a498c14cf Mon Sep 17 00:00:00 2001 From: Dmitrijs Goloscapovs Date: Wed, 11 Dec 2024 13:15:50 +0200 Subject: [PATCH] ...G...... [ZBX-25543] added sanitizing of invalid UTF-8 when monitoring logs --- src/zabbix_agent/logfiles/logfiles.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/zabbix_agent/logfiles/logfiles.c b/src/zabbix_agent/logfiles/logfiles.c index 06c2db1e767..09133467b6d 100644 --- a/src/zabbix_agent/logfiles/logfiles.c +++ b/src/zabbix_agent/logfiles/logfiles.c @@ -2083,9 +2083,16 @@ static int zbx_read2(int fd, unsigned char flags, struct st_logfile *logfile, zb buf[BUF_SIZE] = '\0'; if ('\0' != *encoding) + { value = convert_to_utf8(buf, (size_t)BUF_SIZE, encoding); + } else + { +#ifndef PCRE2_MATCH_INVALID_UTF + zbx_replace_invalid_utf8(buf); +#endif value = buf; + } zabbix_log(LOG_LEVEL_WARNING, "Logfile contains a large record: \"%.64s\"" " (showing only the first 64 characters). Only the first 256 kB" @@ -2216,9 +2223,16 @@ static int zbx_read2(int fd, unsigned char flags, struct st_logfile *logfile, zb *p_nl = '\0'; if ('\0' != *encoding) + { value = convert_to_utf8(p_start, (size_t)(p_nl - p_start), encoding); + } else + { +#ifndef PCRE2_MATCH_INVALID_UTF + zbx_replace_invalid_utf8(p_start); +#endif value = p_start; + } processed_size = (size_t)offset + (size_t)(p_next - buf); send_err = FAIL; -- 2.39.2