summaryrefslogtreecommitdiffstats
path: root/ipv6.c
diff options
context:
space:
mode:
authorRoy Marples <roy@marples.name>2016-05-03 13:55:07 +0000
committerRoy Marples <roy@marples.name>2016-05-03 13:55:07 +0000
commitf137e29cb694ff44ab8388a463f4eaa53e178e24 (patch)
treeede3c683c2ca434328d595d813ca987e1588b20c /ipv6.c
parent6b84d0e00a7ad6b46ef3159a2e5e225271e88ecb (diff)
downloaddhcpcd-f137e29cb694ff44ab8388a463f4eaa53e178e24.tar.xz
Document some coverity false positives.
Diffstat (limited to 'ipv6.c')
-rw-r--r--ipv6.c33
1 files changed, 21 insertions, 12 deletions
diff --git a/ipv6.c b/ipv6.c
index 3bd52068..d1e2d05f 100644
--- a/ipv6.c
+++ b/ipv6.c
@@ -409,21 +409,25 @@ ipv6_makeaddr(struct in6_addr *addr, struct interface *ifp,
int
ipv6_makeprefix(struct in6_addr *prefix, const struct in6_addr *addr, int len)
{
- int bytelen, bitlen;
+ int bytes, bits;
if (len < 0 || len > 128) {
errno = EINVAL;
return -1;
}
- bytelen = len / NBBY;
- bitlen = len % NBBY;
- memcpy(&prefix->s6_addr, &addr->s6_addr, (size_t)bytelen);
- if (bitlen != 0)
- prefix->s6_addr[bytelen] =
- (uint8_t)(prefix->s6_addr[bytelen] >> (NBBY - bitlen));
- memset((char *)prefix->s6_addr + bytelen, 0,
- sizeof(prefix->s6_addr) - (size_t)bytelen);
+ bytes = len / NBBY;
+ bits = len % NBBY;
+ memcpy(&prefix->s6_addr, &addr->s6_addr, (size_t)bytes);
+ if (bits != 0) {
+ /* Coverify false positive.
+ * bytelen cannot be 16 if bitlen is non zero */
+ /* coverity[overrun-local] */
+ prefix->s6_addr[bytes] =
+ (uint8_t)(prefix->s6_addr[bytes] >> (NBBY - bits));
+ }
+ memset((char *)prefix->s6_addr + bytes, 0,
+ sizeof(prefix->s6_addr) - (size_t)bytes);
return 0;
}
@@ -444,8 +448,12 @@ ipv6_mask(struct in6_addr *mask, int len)
bits = len % NBBY;
for (i = 0; i < bytes; i++)
mask->s6_addr[i] = 0xff;
- if (bits)
+ if (bits) {
+ /* Coverify false positive.
+ * bytelen cannot be 16 if bitlen is non zero */
+ /* coverity[overrun-local] */
mask->s6_addr[bytes] = masks[bits - 1];
+ }
return 0;
}
@@ -2350,7 +2358,8 @@ ipv6_buildroutes(struct dhcpcd_ctx *ctx)
}
/* Free any routes we failed to add/change */
- while ((rt = TAILQ_FIRST(&dnr))) {
+ /* coverity[use_after_free] */
+ while ((rt = TAILQ_FIRST(&dnr)) != NULL) {
TAILQ_REMOVE(&dnr, rt, next);
free(rt);
}
@@ -2358,7 +2367,7 @@ ipv6_buildroutes(struct dhcpcd_ctx *ctx)
/* Remove old routes we used to manage
* If we own the default route, but not RA management itself
* then we need to preserve the last best default route we had */
- while ((rt = TAILQ_LAST(ctx->ipv6->routes, rt6_head))) {
+ while ((rt = TAILQ_LAST(ctx->ipv6->routes, rt6_head)) != NULL) {
TAILQ_REMOVE(ctx->ipv6->routes, rt, next);
if (find_route6(nrs, rt) == NULL) {
o = rt->iface->options->options;