]> git.ipfire.org Git - thirdparty/dhcpcd.git/commitdiff
DHCP6: Assert auto sla is only 32-bits
authorRoy Marples <roy@marples.name>
Mon, 22 Jul 2019 11:44:20 +0000 (12:44 +0100)
committerRoy Marples <roy@marples.name>
Mon, 22 Jul 2019 11:44:20 +0000 (12:44 +0100)
It already is due to the use of fls32 above, but this assertion
makes clang static analyser happy.

src/dhcp6.c

index 75473ea89ad1d199c9959a22f098c8893d2367a9..42face2d79fa3b40257dd683271588b5b172e708 100644 (file)
@@ -583,10 +583,14 @@ dhcp6_delegateaddr(struct in6_addr *addr, struct interface *ifp,
 
 #define BIT(n) (1UL << (n))
 #define BIT_MASK(len) (BIT(len) - 1)
-               if (ia->sla_max == 0)
+               if (ia->sla_max == 0) {
                        /* Work out the real sla_max from our bits used */
-                       ia->sla_max = (uint32_t)BIT_MASK(asla.prefix_len -
-                           prefix->prefix_len);
+                       bits = asla.prefix_len - prefix->prefix_len;
+                       /* Make static analysis happy.
+                        * Bits cannot be bigger than 32 thanks to fls32. */
+                       assert(bits <= 32);
+                       ia->sla_max = (uint32_t)BIT_MASK(bits);
+               }
        }
 
        if (ipv6_userprefix(&prefix->prefix, prefix->prefix_len,