From af08767885c24c50b751a4d7757200d1fce9cbb8 Mon Sep 17 00:00:00 2001 From: Takahiro Yamashita Date: Sun, 4 Feb 2024 18:46:18 +0900 Subject: [PATCH] filter_nest: define a new var to prevent pointer arithmetic An arg of FLB_LOG_EVENT_STRING_LENGTH_VALUE is a flb_log_event_encoder_size_t. flb_log_event_encoder_size_t is size_t* on Windows. It can cause pointer arithmetic and the output can be larger value. We use 'new_size' to prevent pointer arithmetic. Signed-off-by: Takahiro Yamashita --- plugins/filter_nest/nest.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/plugins/filter_nest/nest.c b/plugins/filter_nest/nest.c index c63376fbda2..2ace2137e81 100644 --- a/plugins/filter_nest/nest.c +++ b/plugins/filter_nest/nest.c @@ -198,9 +198,19 @@ static void helper_pack_string_add_prefix(struct flb_log_event_encoder *log_enco const char *str, int len) { + size_t new_size; + + /* + An arg of FLB_LOG_EVENT_STRING_LENGTH_VALUE is a flb_log_event_encoder_size_t. + flb_log_event_encoder_size_t is size_t* on Windows. + It can cause pointer arithmetic and the output can be larger value. + We use 'new_size' to prevent pointer arithmetic. + */ + new_size = ctx->prefix_len + len; + flb_log_event_encoder_append_body_values( log_encoder, - FLB_LOG_EVENT_STRING_LENGTH_VALUE(ctx->prefix_len + len), + FLB_LOG_EVENT_STRING_LENGTH_VALUE(new_size), FLB_LOG_EVENT_STRING_BODY_VALUE(ctx->prefix, ctx->prefix_len), FLB_LOG_EVENT_STRING_BODY_VALUE(str, len)); }