It seems the broadcast address parameter is not optional now, if users haven't
specified the broadcast address to the network interface then a segfault will
be raised.
This patch is just a temporary solution to avoid segfault, and with the patch,
users will get a expected error "Unable to parse networks: Unable to parse
broadcast address (null)", of course, a better patch should automatically
generate a broadcast address according to actual ip address. But AFAIK,
the IPv6 hasn't defined broadcast address, so it needs to do address protocol
judgement firstly, I will try to implement it later.
* How to reproduce?
# virt-sandbox -c lxc:/// --network address=192.168.122.1 /bin/sh
or
# virt-sandbox -c lxc:/// --network address=192.168.122.1/24 /bin/sh
Signed-off-by: Alex Jia <ajia(a)redhat.com>
---
libvirt-sandbox/libvirt-sandbox-config.c | 8 ++++++++
1 files changed, 8 insertions(+), 0 deletions(-)
diff --git a/libvirt-sandbox/libvirt-sandbox-config.c
b/libvirt-sandbox/libvirt-sandbox-config.c
index 3dc453a..f392f4b 100644
--- a/libvirt-sandbox/libvirt-sandbox-config.c
+++ b/libvirt-sandbox/libvirt-sandbox-config.c
@@ -873,6 +873,14 @@ gboolean gvir_sandbox_config_add_network_strv(GVirSandboxConfig
*config,
goto cleanup;
}
+ if (!bcast) {
+ g_set_error(error, GVIR_SANDBOX_CONFIG_ERROR, 0,
+ "Unable to parse broadcast address %s",
bcast);
+ g_free(primary);
+ goto cleanup;
+
+ }
+
if (!(bcastaddr = g_inet_address_new_from_string(bcast))) {
g_set_error(error, GVIR_SANDBOX_CONFIG_ERROR, 0,
"Unable to parse address %s", bcast);
--
1.7.1