From 738fe10500fb47fe67535f60b3f77325a15f92a1 Mon Sep 17 00:00:00 2001 From: David Korczynski Date: Fri, 22 Sep 2023 21:29:39 +0100 Subject: [PATCH 1/2] config_format: fix memory leak There can be multiple states needing to be popped in the event of errors. Fixes: https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=61733 Signed-off-by: David Korczynski --- src/config_format/flb_cf_yaml.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/config_format/flb_cf_yaml.c b/src/config_format/flb_cf_yaml.c index 5fc42bdcb1d..2a571e59ea9 100644 --- a/src/config_format/flb_cf_yaml.c +++ b/src/config_format/flb_cf_yaml.c @@ -2039,7 +2039,9 @@ static int read_config(struct flb_cf *conf, struct local_ctx *ctx, } yaml_parser_delete(&parser); - state_pop(ctx); + + /* free all remaining states */ + while (state = state_pop(ctx)); fclose(fh); ctx->level--; From f15221165bba8b588e607f8a8d0ad083eb55b588 Mon Sep 17 00:00:00 2001 From: David Korczynski Date: Tue, 26 Sep 2023 06:17:57 +0100 Subject: [PATCH 2/2] config_format: adjust leak fix Signed-off-by: David Korczynski --- src/config_format/flb_cf_yaml.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/config_format/flb_cf_yaml.c b/src/config_format/flb_cf_yaml.c index 2a571e59ea9..289760ec7c0 100644 --- a/src/config_format/flb_cf_yaml.c +++ b/src/config_format/flb_cf_yaml.c @@ -2041,7 +2041,12 @@ static int read_config(struct flb_cf *conf, struct local_ctx *ctx, yaml_parser_delete(&parser); /* free all remaining states */ - while (state = state_pop(ctx)); + if (code == -1) { + while (state = state_pop(ctx)); + } + else { + state = state_pop(ctx); + } fclose(fh); ctx->level--;