]> git.ipfire.org Git - thirdparty/lxc.git/commitdiff
lxccontainer: fix lxc_config_item_is_supported 3564/head
authorRuben Jenster <r.jenster@drachenfels.de>
Fri, 23 Oct 2020 16:32:15 +0000 (18:32 +0200)
committerRuben Jenster <r.jenster@drachenfels.de>
Tue, 27 Oct 2020 08:47:55 +0000 (09:47 +0100)
Use exact match instead of longest prefix match
to check whether a config item is supported.

Signed-off-by: Ruben Jenster <r.jenster@drachenfels.de>
src/lxc/confile.c
src/lxc/confile.h
src/lxc/lxccontainer.c
src/tests/get_item.c

index 75587d0ac8f155231b622ad398fecf43fcd359bc..08dd6916673b8d4c8dfe0425db48a6da6d6bac83 100644 (file)
@@ -278,6 +278,18 @@ static struct lxc_config_t config_jump_table[] = {
 
 static const size_t config_jump_table_size = sizeof(config_jump_table) / sizeof(struct lxc_config_t);
 
+struct lxc_config_t *lxc_get_config_exact(const char *key)
+{
+       size_t i;
+
+       for (i = 0; i < config_jump_table_size; i++)
+               if (!strcmp(config_jump_table[i].name, key))
+                       return &config_jump_table[i];
+
+       return NULL;
+}
+
+
 struct lxc_config_t *lxc_get_config(const char *key)
 {
        size_t i;
index df80f639a38be68fa61064e12cdf4d15fe88216d..68d50fc804c598b981c1023f17d7c7d6d222f289 100644 (file)
@@ -45,6 +45,9 @@ struct new_config_item {
 };
 
 /* Get the jump table entry for the given configuration key. */
+__hidden extern struct lxc_config_t *lxc_get_config_exact(const char *key);
+
+/* Get the jump table entry if entry name is a prefix of the given configuration key. */
 __hidden extern struct lxc_config_t *lxc_get_config(const char *key);
 
 /* List all available config items. */
index 673cf2483d99db0363b2d9f5c7d9db24d3195a3b..96aa372e1ddaabf761f289766dd959c87a4763c3 100644 (file)
@@ -5749,7 +5749,7 @@ free_ct_name:
 
 bool lxc_config_item_is_supported(const char *key)
 {
-       return !!lxc_get_config(key);
+       return !!lxc_get_config_exact(key);
 }
 
 bool lxc_has_api_extension(const char *extension)
index f2757c29d89fa10909611d0d02fb4f446eefa992..11db5f6738fb294bbf14fb7005467aa26eb4015f 100644 (file)
@@ -600,6 +600,11 @@ int main(int argc, char *argv[])
                goto out;
        }
 
+       if (lxc_config_item_is_supported("lxc.arch.nonsense")) {
+               fprintf(stderr, "%d: failed to detect \"lxc.arch.nonsense\" as unsupported configuration item\n", __LINE__);
+               goto out;
+       }
+
        if (c->set_config_item(c, "lxc.notaconfigkey", "invalid")) {
                fprintf(stderr, "%d: Managed to set \"lxc.notaconfigkey\"\n", __LINE__);
                goto out;