]> xenbits.xensource.com Git - libvirt.git/commitdiff
lxc: Fix segfault when lxc.network does not start with 'type'
authorJulio Faracco <jcfaracco@gmail.com>
Thu, 6 Feb 2020 02:12:05 +0000 (23:12 -0300)
committerMichal Privoznik <mprivozn@redhat.com>
Thu, 6 Feb 2020 13:57:17 +0000 (14:57 +0100)
To configure network settings using config file, legacy LXC settings
require starting them with 'lxc.network.type' entry. If someone
accidentally starts with 'lxc.network.name', libvirt will crash with
segfault. This patch checks if this case is happening.

Sample invalid settings:
lxc.network.link = eth0
lxc.network.type = phys
lxc.network.name = eth1
lxc.network.ipv4 = 192.168.122.2/24
lxc.network.ipv4.gateway = 192.168.122.1

Now, libvirt only see error without segmentation fault.

Signed-off-by: Julio Faracco <jcfaracco@gmail.com>
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
src/lxc/lxc_native.c

index 59f3dd4feebd87db5025cb7e37725e2a75c52f5f..7e8492a36614515f6441aaab0f1ffe82396d2281 100644 (file)
@@ -717,7 +717,11 @@ lxcNetworkGetParseDataByIndexLegacy(lxcNetworkParseDataArray *networks,
     }
 
     /* Return last element added like a stack. */
-    return networks->parseData[ndata - 1];
+    if (ndata > 0)
+        return networks->parseData[ndata - 1];
+
+    /* Not able to retrive an element */
+    return NULL;
 }