From: Willy Tarreau Date: Tue, 17 May 2016 14:16:09 +0000 (+0200) Subject: CLEANUP: config: detect double registration of a config section X-Git-Tag: v1.7-dev4~109 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=5e4261b;p=thirdparty%2Fhaproxy.git 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. --- 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);