]> git.ipfire.org Git - thirdparty/ulogd2.git/commitdiff
ulogd: raise error on unknown config key
authorCorubba Smith <corubba@gmx.de>
Wed, 12 Mar 2025 19:09:36 +0000 (20:09 +0100)
committerFlorian Westphal <fw@strlen.de>
Wed, 12 Mar 2025 19:11:22 +0000 (20:11 +0100)
Until a6fbeb96e889 ("new configuration file syntax (Magnus Boden)")
this was already caught, and the enum member is still present.

Check if the for loop worked throught the whole array without hitting a
matching config option, and return with the unknown key error code.
Because there is no existing config_entry struct with that unknwon key
to use with the established config_errce pointer, allocate a new struct.
This potentially creates a memory leak if that config_entry is never
freed again, but for me that is acceptable in this rare case.

Since the memory allocation for the struct can fail, also reuse the old
out-of-memory error to indicate that.

Signed-off-by: Corubba Smith <corubba@gmx.de>
Signed-off-by: Florian Westphal <fw@strlen.de>
src/conffile.c
src/ulogd.c

index e55ff30b2ac833878db4444f9c06bb7084b5cb1c..f84fcf5620d7850a15505461b92166ce5485da46 100644 (file)
@@ -256,6 +256,18 @@ int config_parse_file(const char *section, struct config_keyset *kset)
                        break;
                }
                pr_debug("parse_file: exiting main loop\n");
+
+               if (i == kset->num_ces) {
+                       config_errce = calloc(1, sizeof(struct config_entry));
+                       if (config_errce == NULL) {
+                               err = -ERROOM;
+                               goto cpf_error;
+                       }
+                       memcpy(&config_errce->key[0], wordbuf,
+                              sizeof(config_errce->key) - 1);
+                       err = -ERRUNKN;
+                       goto cpf_error;
+               }
        }
 
 
index b146f94cc8e626066738120deb4d44be4964cb43..917ae3a99df01e86a8c92c8bbe1b4f19d40c884b 100644 (file)
@@ -281,6 +281,8 @@ int ulogd_parse_configfile(const char *section, struct config_keyset *ce)
        case -ERRUNKN:
                ulogd_log(ULOGD_ERROR, "unknown config key \"%s\"\n",
                          config_errce->key);
+               free(config_errce);
+               config_errce = NULL;
                break;
        case -ERRSECTION:
                ulogd_log(ULOGD_ERROR, "section \"%s\" not found\n", section);