]> git.ipfire.org Git - people/ms/dnsmasq.git/commitdiff
Fix length->netmask conversions to avoid undefined behaviour.
authorRichard Genoud <richard.genoud@gmail.com>
Wed, 17 Sep 2014 20:17:39 +0000 (21:17 +0100)
committerSimon Kelley <simon@thekelleys.org.uk>
Wed, 17 Sep 2014 20:17:39 +0000 (21:17 +0100)
src/auth.c
src/netlink.c

index 066a9e449b832825208e6215a4a8c576d075b893..dd46566ec2ccb7cec0006c20a512d164ca9a376f 100644 (file)
@@ -31,7 +31,7 @@ static struct addrlist *find_subnet(struct auth_zone *zone, int flag, struct all
          if (!(flag & F_IPV4))
            continue;
          
-         netmask.s_addr = htonl(~((1 << (32 - subnet->prefixlen)) - 1));
+         netmask.s_addr = htonl(~(in_addr_t)0 << (32 - subnet->prefixlen));
          
          if  (is_same_net(addr, subnet->addr.addr.addr4, netmask))
            return subnet;
index cff43cc46b050f642ba3a0f1a7412e4721f76802..b393283763894ff179caa62db8e4e703e68f3556 100644 (file)
@@ -208,7 +208,8 @@ int iface_enumerate(int family, void *parm, int (*callback)())
                    struct in_addr netmask, addr, broadcast;
                    char *label = NULL;
 
-                   netmask.s_addr = htonl(0xffffffff << (32 - ifa->ifa_prefixlen));
+                   netmask.s_addr = htonl(~(in_addr_t)0 << (32 - ifa->ifa_prefixlen));
+
                    addr.s_addr = 0;
                    broadcast.s_addr = 0;