From: Thomas Parrott Date: Tue, 9 Jun 2020 11:03:06 +0000 (+0100) Subject: network: Fix coverity issue, leaking data in lxc_ovs_setup_bridge_vlan_exec X-Git-Tag: lxc-5.0.0~421^2~5 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=785e15403e7a004a285686342e6d4b973e278803;p=thirdparty%2Flxc.git network: Fix coverity issue, leaking data in lxc_ovs_setup_bridge_vlan_exec Signed-off-by: Thomas Parrott --- diff --git a/src/lxc/network.c b/src/lxc/network.c index 2ff053eca..9691ec94a 100644 --- a/src/lxc/network.c +++ b/src/lxc/network.c @@ -433,11 +433,14 @@ struct ovs_veth_vlan_args { static int lxc_ovs_setup_bridge_vlan_exec(void *data) { struct ovs_veth_vlan_args *args = data; - const char *vlan_mode = "", *tag = "", *trunks = ""; + __do_free char *vlan_mode = NULL, *tag = NULL, *trunks = NULL; + + if (!args->vlan_mode) + return ret_errno(EINVAL); vlan_mode = must_concat(NULL, "vlan_mode=", args->vlan_mode, (char *)NULL); - if (args->vlan_id >= 0) { + if (args->vlan_id > BRIDGE_VLAN_NONE) { char buf[5]; int rc; @@ -449,15 +452,15 @@ static int lxc_ovs_setup_bridge_vlan_exec(void *data) } - if (strcmp(args->trunks, "") != 0) + if (args->trunks) trunks = must_concat(NULL, "trunks=", args->trunks, (char *)NULL); /* Detect the combination of vlan_id and trunks specified and convert to ovs-vsctl command. */ - if (strcmp(tag, "") != 0 && strcmp(trunks, "") != 0) + if (tag && trunks) execlp("ovs-vsctl", "ovs-vsctl", "set", "port", args->nic, vlan_mode, tag, trunks, (char *)NULL); - else if (strcmp(tag, "") != 0) + else if (tag) execlp("ovs-vsctl", "ovs-vsctl", "set", "port", args->nic, vlan_mode, tag, (char *)NULL); - else if (strcmp(trunks, "") != 0) + else if (trunks) execlp("ovs-vsctl", "ovs-vsctl", "set", "port", args->nic, vlan_mode, trunks, (char *)NULL); else return -EINVAL;