1
0
mirror of https://gitlab.com/libvirt/libvirt.git synced 2024-12-22 17:34:18 +03:00

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 <jcfaracco@gmail.com>
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
This commit is contained in:
Julio Faracco 2020-02-05 23:12:05 -03:00 committed by Michal Privoznik
parent 933ad86002
commit 991c56105d

View 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;
}