Fix error in IPv6 prefix calculation.

Error with prefixed address assignment. When it is calculating number of
addresses from prefixlen, it rotates only 32bit int instead of 64b uint.
Only result is assigned to 64b variable.

Two examples:

dhcp-host=[2000::1230:0:0/92],correct-prefix
dhcp-host=[2000::1234:5678:0/92],incorrect-prefix

If prefix length is lower than 96, the result is zero. It means
incorrect-prefix is not refused as it should. Fix is simple, attaching
patch with it. Just rotate 64b int.
This commit is contained in:
Petr Menšík
2020-03-08 15:56:19 +00:00
committed by Simon Kelley
parent dded78b233
commit 46bdfe691a
2 changed files with 2 additions and 2 deletions

View File

@@ -3322,7 +3322,7 @@ static int one_opt(int option, char *arg, char *errstr, char *gen_err, int comma
if (!atoi_check(pref, &new_addr->prefixlen) || if (!atoi_check(pref, &new_addr->prefixlen) ||
new_addr->prefixlen > 128 || new_addr->prefixlen > 128 ||
(((1<<(128-new_addr->prefixlen))-1) & addrpart) != 0) ((((u64)1<<(128-new_addr->prefixlen))-1) & addrpart) != 0)
{ {
dhcp_config_free(new); dhcp_config_free(new);
ret_err(_("bad IPv6 prefix")); ret_err(_("bad IPv6 prefix"));

View File

@@ -1731,7 +1731,7 @@ static int config_valid(struct dhcp_config *config, struct dhcp_context *context
addresses = 1; addresses = 1;
if (addr_list->flags & ADDRLIST_PREFIX) if (addr_list->flags & ADDRLIST_PREFIX)
addresses = 1<<(128-addr_list->prefixlen); addresses = (u64)1<<(128-addr_list->prefixlen);
if ((addr_list->flags & ADDRLIST_WILDCARD)) if ((addr_list->flags & ADDRLIST_WILDCARD))
{ {