]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
config: Fix memory leak on config parsing failure
authorTimo Sirainen <timo.sirainen@open-xchange.com>
Wed, 3 May 2023 09:29:26 +0000 (12:29 +0300)
committerTimo Sirainen <timo.sirainen@open-xchange.com>
Mon, 20 Nov 2023 12:21:56 +0000 (14:21 +0200)
src/config/config-filter.c
src/config/config-parser.c
src/config/config-parser.h
src/config/doveconf.c

index e118b06fb361c2e556e5c9fe6c25ec13b7f67e14..c325c8e9456533168f2cc697a95df3165e167c39 100644 (file)
@@ -117,6 +117,7 @@ struct config_filter_context *config_filter_init(pool_t pool)
 
        ctx = p_new(pool, struct config_filter_context, 1);
        ctx->pool = pool;
+       pool_ref(ctx->pool);
        p_array_init(&ctx->errors, pool, 1);
        return ctx;
 }
index e9af29d6df04ebe72e0ec87c6cf58e3386e4ce91..15bd86dd1c4b6bf3073c0d7284e4c70a8a7725e0 100644 (file)
@@ -755,6 +755,7 @@ config_parse_line(struct config_parser_context *ctx,
 
 static int
 config_parse_finish(struct config_parser_context *ctx,
+                   enum config_parse_flags flags,
                    struct config_filter_context **filter_r,
                    const char **error_r)
 {
@@ -776,6 +777,10 @@ config_parse_finish(struct config_parser_context *ctx,
                                           ctx->path, error);
        }
 
+       if (ret < 0 && (flags & CONFIG_PARSE_FLAG_RETURN_BROKEN_CONFIG) == 0) {
+               config_filter_deinit(&new_filter);
+               return -1;
+       }
        config_module_parsers = ctx->root_parsers;
        *filter_r = new_filter;
        return ret;
@@ -1119,7 +1124,8 @@ prevfile:
        hash_table_destroy(&ctx.seen_settings);
        str_free(&full_line);
        if (ret == 0)
-               ret = config_parse_finish(&ctx, filter_r, error_r);
+               ret = config_parse_finish(&ctx, flags, filter_r, error_r);
+       pool_unref(&ctx.pool);
        return ret < 0 ? ret : 1;
 }
 
index 593974c217e993ccf587e4e23b637891b51fa985..f993075cf0b4cbde0383eca53e357def904eb797 100644 (file)
@@ -11,6 +11,7 @@ enum config_parse_flags {
        CONFIG_PARSE_FLAG_EXPAND_VALUES = BIT(0),
        CONFIG_PARSE_FLAG_HIDE_OBSOLETE_WARNINGS = BIT(1),
        CONFIG_PARSE_FLAG_DELAY_ERRORS  = BIT(3),
+       CONFIG_PARSE_FLAG_RETURN_BROKEN_CONFIG = BIT(4),
 };
 
 struct config_module_parser {
index 1a671d0f300f8b545176e2532582c6916e591825..9eebc619ec222d087008198a3030090ac5a2bdb3 100644 (file)
@@ -920,7 +920,7 @@ int main(int argc, char *argv[])
                }
        }
 
-       enum config_parse_flags flags = 0;
+       enum config_parse_flags flags = CONFIG_PARSE_FLAG_RETURN_BROKEN_CONFIG;
        if (expand_vars)
                flags |= CONFIG_PARSE_FLAG_EXPAND_VALUES;
        if (dump_full && exec_args != NULL && !check_full_config)