[libvirt] [libvirt-sandbox][PATCH] Avoid segfault if broadcast address is NULL

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@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

On Thu, Mar 14, 2013 at 07:00:43PM +0800, Alex Jia wrote:
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.
I think that if you don't explicitly set a broadcast address, then the kernel will set one on the device based on its address/netmask. So I think you can just allow a NULL bcast value everywhere in virt-sandbox code. Daniel -- |: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :| |: http://libvirt.org -o- http://virt-manager.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :|

On 03/14/2013 07:16 PM, Daniel P. Berrange wrote:
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. I think that if you don't explicitly set a broadcast address, then the kernel will set one on the device based on its address/netmask. So I
On Thu, Mar 14, 2013 at 07:00:43PM +0800, Alex Jia wrote: think you can just allow a NULL bcast value everywhere in virt-sandbox code.
Daniel
Daniel, got it and thanks for your nice comments, but I think a segmentation fault (core dumped) isn't very friendly for users after all, or should we apply a patch to allow NULL in g_inet_address_new_from_string()? Regards, Alex
participants (2)
-
Alex Jia
-
Daniel P. Berrange