]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
CLEANUP: config: detect double registration of a config section
authorWilly Tarreau <w@1wt.eu>
Tue, 17 May 2016 14:16:09 +0000 (16:16 +0200)
committerWilly Tarreau <w@1wt.eu>
Tue, 17 May 2016 14:18:31 +0000 (16:18 +0200)
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

index 2400559d95d90f30d4b0e7ab8d648a0a5f0f477c..3fee54e0db1d34fe8712e4e8f45571c93989da79 100644 (file)
@@ -9098,6 +9098,13 @@ int cfg_register_section(char *section_name,
 {
        struct cfg_section *cs;
 
+       list_for_each_entry(cs, &sections, 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);