From 5e4261b0e469d176e075b41778b07df83f5c7c77 Mon Sep 17 00:00:00 2001 From: Willy Tarreau Date: Tue, 17 May 2016 16:16:09 +0200 Subject: [PATCH] CLEANUP: config: detect double registration of a config section In an effort to make the config parser more robust, we should validate that everything we register is not already registered. Most cfg_register_* functions unfortunately return void and just perform a LIST_ADDQ(), so they will have to change for this. At least cfg_register_section() does perform a bit of checks and is easy to check for such errors, so let's start with this one. Future patches will definitely have to focus on the remaining functions and ensure unicity of all config parsers. --- src/cfgparse.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/cfgparse.c b/src/cfgparse.c index 2400559d95..3fee54e0db 100644 --- a/src/cfgparse.c +++ b/src/cfgparse.c @@ -9098,6 +9098,13 @@ int cfg_register_section(char *section_name, { struct cfg_section *cs; + list_for_each_entry(cs, §ions, list) { + if (strcmp(cs->section_name, section_name) == 0) { + Alert("register section '%s': already registered.\n", section_name); + return 0; + } + } + cs = calloc(1, sizeof(*cs)); if (!cs) { Alert("register section '%s': out of memory.\n", section_name); -- 2.39.5