summaryrefslogtreecommitdiffstats
path: root/ipv6.c
diff options
context:
space:
mode:
authorRoy Marples <roy@marples.name>2016-01-29 10:18:02 +0000
committerRoy Marples <roy@marples.name>2016-01-29 10:18:02 +0000
commitf5eb2f87816521135495ad3a6b611de341c70ec3 (patch)
tree5fb1f73126ef1f54def705494dfbc6dc6d3f3a95 /ipv6.c
parent40095c803a2c001600be75a0adecf8409e67d335 (diff)
downloaddhcpcd-f5eb2f87816521135495ad3a6b611de341c70ec3.tar.xz
Use ffs64(3) instead of ffs(3) when calculating to see if we can fit the
user number inside the resultant length given the prefix length, so we can use the whole of the user number (64 bits) if needed. Add a compat ffs64(3) implementation from NetBSD if none found on the platform.
Diffstat (limited to 'ipv6.c')
-rw-r--r--ipv6.c12
1 files changed, 8 insertions, 4 deletions
diff --git a/ipv6.c b/ipv6.c
index 2b383bd2..7e77b966 100644
--- a/ipv6.c
+++ b/ipv6.c
@@ -37,6 +37,10 @@
#include "config.h"
+#ifdef HAVE_SYS_BITOPS_H
+#include <sys/bitops.h>
+#endif
+
#ifdef BSD
/* Purely for the ND6_IFF_AUTO_LINKLOCAL #define which is solely used
* to generate our CAN_ADD_LLADDR #define. */
@@ -518,16 +522,16 @@ ipv6_userprefix(
{
uint64_t vh, vl, user_low, user_high;
- if (prefix_len < 0 || prefix_len > 120 ||
- result_len < 0 || result_len > 120)
+ if (prefix_len < 0 || prefix_len > 128 ||
+ result_len < 0 || result_len > 128)
{
errno = EINVAL;
return -1;
}
/* Check that the user_number fits inside result_len less prefix_len */
- if (result_len < prefix_len || user_number > INT_MAX ||
- ffs((int)user_number) > result_len - prefix_len)
+ if (result_len < prefix_len ||
+ ffs64(user_number) > result_len - prefix_len)
{
errno = ERANGE;
return -1;