Skip to content

Commit

Permalink
in stdin: Initialize memory to 0
Browse files Browse the repository at this point in the history
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 fluent#4544 will then pop up
randomly.

This fix was validated with valgrind and the example provided in fluent#4544
  • Loading branch information
ptsneves committed Feb 7, 2022
1 parent d4d2c33 commit da988f3
Showing 1 changed file with 1 addition and 0 deletions.
1 change: 1 addition & 0 deletions plugins/in_stdin/in_stdin.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit da988f3

Please sign in to comment.