From: Timo Sirainen Date: Thu, 15 May 2025 10:26:30 +0000 (+0300) Subject: lib-settings, config: Panic if SETTING_DEFINE_LIST_END is missing from settings lists X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=7dcff58c41170d02a286bc4f082c5f3b60222eb9;p=thirdparty%2Fdovecot%2Fcore.git lib-settings, config: Panic if SETTING_DEFINE_LIST_END is missing from settings lists --- diff --git a/src/config/config-parser.c b/src/config/config-parser.c index b7ddab8919..654f918594 100644 --- a/src/config/config-parser.c +++ b/src/config/config-parser.c @@ -2910,10 +2910,17 @@ config_parser_add_info(struct config_parser_context *ctx, const struct setting_parser_info *info = all_infos[info_idx]; struct config_parser_key *config_key, *old_config_key; const char *name; + unsigned int i = 0; - for (unsigned int i = 0; info->defines[i].key != NULL; i++) { + for (i = 0; info->defines[i].key != NULL; i++) { const struct setting_define *def = &info->defines[i]; + if ((info->defines[i].flags & SET_FLAG_EOL) != 0) { + i_panic("struct %s key %s contains SET_FLAG_EOL", + info->name, def->key); + } + + i_assert((def->flags & SET_FLAG_EOL) == 0); if (def->type == SET_STR || def->type == SET_STR_NOVARS || def->type == SET_ENUM) { @@ -2949,6 +2956,10 @@ config_parser_add_info(struct config_parser_context *ctx, DLLIST_PREPEND(&old_config_key, config_key); hash_table_update(ctx->all_keys, def->key, config_key); } + if ((info->defines[i].flags & SET_FLAG_EOL) == 0) { + i_panic("struct %s is missing SETTING_DEFINE_LIST_END", + info->name); + } } static void diff --git a/src/lib-settings/settings-parser.h b/src/lib-settings/settings-parser.h index f2bbd4b95c..3af52dda7f 100644 --- a/src/lib-settings/settings-parser.h +++ b/src/lib-settings/settings-parser.h @@ -49,6 +49,8 @@ enum setting_type { }; enum setting_flags { SET_FLAG_HIDDEN = BIT(0), + /* Used only for SETTING_DEFINE_LIST_END */ + SET_FLAG_EOL = BIT(1), }; enum setting_apply_flags { @@ -58,7 +60,7 @@ enum setting_apply_flags { SETTING_APPLY_FLAG_NO_EXPAND = BIT(1), }; -#define SETTING_DEFINE_LIST_END { 0, 0, NULL, 0, NULL, NULL, NULL } +#define SETTING_DEFINE_LIST_END { 0, SET_FLAG_EOL, NULL, 0, NULL, NULL, NULL } struct setting_filter_array_order { const struct setting_parser_info *info;