From: Felix Abecassis Date: Wed, 29 Nov 2017 04:27:44 +0000 (-0800) Subject: confile: error out if a network configuration key has no subkey X-Git-Tag: lxc-3.0.0.beta1~146^2~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=24fa7df6f16755f52add95ba52edeb67c6cb9324;p=thirdparty%2Flxc.git confile: error out if a network configuration key has no subkey This prevent an infinite recursion in the case of "lxc.net.0. = a" Signed-off-by: Felix Abecassis --- diff --git a/src/lxc/confile.c b/src/lxc/confile.c index c6a0aeef9..a2e5ba7c1 100644 --- a/src/lxc/confile.c +++ b/src/lxc/confile.c @@ -3801,6 +3801,10 @@ static struct lxc_config_t *get_network_config_ops(const char *key, /* lxc.net.. */ if (idx_end) { *idx_end = '.'; + if (strlen(idx_end + 1) == 0) { + ERROR("No subkey in network configuration key \"%s\"", key); + goto on_error; + } memmove(copy + 8, idx_end + 1, strlen(idx_end + 1)); copy[strlen(key) - numstrlen + 1] = '\0'; diff --git a/src/lxc/confile_legacy.c b/src/lxc/confile_legacy.c index 209ae71f3..eb956dd40 100644 --- a/src/lxc/confile_legacy.c +++ b/src/lxc/confile_legacy.c @@ -90,6 +90,10 @@ int set_config_network_legacy_nic(const char *key, const char *value, if (!p) goto out; + if (strlen(p + 1) == 0) { + ERROR("No subkey in network configuration key \"%s\"", key); + goto out; + } strcpy(copy + 12, p + 1); config = lxc_get_config(copy); if (!config) { diff --git a/src/tests/parse_config_file.c b/src/tests/parse_config_file.c index 7479793ac..c679acc28 100644 --- a/src/tests/parse_config_file.c +++ b/src/tests/parse_config_file.c @@ -166,6 +166,16 @@ static int set_invalid_netdev(struct lxc_container *c) { return -1; } + if (c->set_config_item(c, "lxc.net.0.", "veth")) { + lxc_error("%s\n", "lxc.net.0. should be invalid"); + return -1; + } + + if (c->set_config_item(c, "lxc.network.0.", "veth")) { + lxc_error("%s\n", "lxc.network.0. should be invalid"); + return -1; + } + c->clear_config(c); c->lxc_conf = NULL;