dhcpv4: avoid segfault when there's no IPv4 prefix
authorHans Dedecker <dedeckeh@gmail.com>
Mon, 3 Jul 2017 14:39:21 +0000 (16:39 +0200)
committerHans Dedecker <dedeckeh@gmail.com>
Wed, 13 Sep 2017 13:32:07 +0000 (15:32 +0200)
Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
src/dhcpv4.c

index c7ac058b5d9396e8ff4a83adca2441d0110f0875..b0a4603acdfce156b646b8556d92031a3dc2dcc7 100644 (file)
@@ -95,7 +95,8 @@ int setup_dhcpv4_interface(struct interface *iface, bool enable)
                        return -1;
                }
 
                        return -1;
                }
 
-               uint32_t mask = iface->addr4[0].prefix ? htonl(~((1 << (32 - iface->addr4[0].prefix)) - 1)) : 0;
+               uint32_t mask = iface->addr4 && iface->addr4[0].prefix ?
+                       htonl(~((1 << (32 - iface->addr4[0].prefix)) - 1)) : 0xffffffff;
 
                /* Create a range if not specified */
                if (!(iface->dhcpv4_start.s_addr & htonl(0xffff0000)) &&
 
                /* Create a range if not specified */
                if (!(iface->dhcpv4_start.s_addr & htonl(0xffff0000)) &&