From 991c56105d6e06deed2ab0505cdcd678cea64ef3 Mon Sep 17 00:00:00 2001 From: Julio Faracco Date: Wed, 5 Feb 2020 23:12:05 -0300 Subject: [PATCH] lxc: Fix segfault when lxc.network does not start with 'type' 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 Signed-off-by: Michal Privoznik Reviewed-by: Michal Privoznik --- src/lxc/lxc_native.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/lxc/lxc_native.c b/src/lxc/lxc_native.c index 59f3dd4fee..7e8492a366 100644 --- a/src/lxc/lxc_native.c +++ b/src/lxc/lxc_native.c @@ -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; }