From 11e770d6fb808d69c1e25be77bf10b11e53aa6d4 Mon Sep 17 00:00:00 2001 From: Paulo Neves Date: Mon, 7 Feb 2022 19:14:40 +0100 Subject: [PATCH] in stdin: Initialize memory to 0 in_stdin_collect tests !ctx->parser to decide whether a parser is associated with the context or not. The problem with that check is ctx->parser is not explictily initialized in in_stdin_init and the malloc allocation does not guarantee that the memory assigned to ctx, and ctx->parser is zero initialized. This then will lead to undefined behavior where sometimes the ctx->parser will not be 0 and a non existing parser used. Errors like #4544 will then pop up randomly. This fix was validated with valgrind and the example provided in #4544 Signed-off-by: Paulo Neves --- plugins/in_stdin/in_stdin.c | 1 + 1 file changed, 1 insertion(+) diff --git a/plugins/in_stdin/in_stdin.c b/plugins/in_stdin/in_stdin.c index 427aacd8d21..692e54a3c53 100644 --- a/plugins/in_stdin/in_stdin.c +++ b/plugins/in_stdin/in_stdin.c @@ -279,6 +279,7 @@ static int in_stdin_init(struct flb_input_instance *in, if (!ctx) { return -1; } + memset(ctx, 0, sizeof(struct flb_in_stdin_config)); /* Initialize stdin config */ ret = in_stdin_config_init(ctx, in, config);