From: Roy Marples Date: Sat, 24 Nov 2012 20:36:20 +0000 (+0000) Subject: Avoid sillyness if not a valid IPv6 address X-Git-Tag: v5.6.4~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9664cc0e6c1924947de0e26716c74c9d43992290;p=thirdparty%2Fdhcpcd.git Avoid sillyness if not a valid IPv6 address --- diff --git a/ipv6rs.c b/ipv6rs.c index 0ca5b179..f48d01c7 100644 --- a/ipv6rs.c +++ b/ipv6rs.c @@ -378,7 +378,7 @@ add_router(struct ra *router) void ipv6rs_handledata(_unused void *arg) { - ssize_t len, l, n, olen; + ssize_t len, l, m, n, olen; struct cmsghdr *cm; int hoplimit; struct in6_pktinfo pkt; @@ -632,22 +632,34 @@ ipv6rs_handledata(_unused void *arg) for (n = ndo->nd_opt_len - 1; n > 1; n -= 2, op += sizeof(addr.s6_addr)) { - l += ipv6_printaddr(NULL, 0, op, ifp->name) + 1; + m = ipv6_printaddr(NULL, 0, op, ifp->name); + if (m != -1) + l += m + 1; } op = (uint8_t *)ndo; op += offsetof(struct nd_opt_rdnss, nd_opt_rdnss_lifetime); op += sizeof(rdnss->nd_opt_rdnss_lifetime); tmp = opt = malloc(l); - for (n = ndo->nd_opt_len - 1; n > 1; n -= 2, - op += sizeof(addr.s6_addr)) - { - tmp += ipv6_printaddr(tmp, l, op, ifp->name); - *tmp++ = ' '; - if (lifetime > 0) - has_dns = 1; + if (opt) { + for (n = ndo->nd_opt_len - 1; n > 1; n -= 2, + op += sizeof(addr.s6_addr)) + { + m = ipv6_printaddr(tmp, l, op, + ifp->name); + if (m != -1) { + l -= (m + 1); + tmp += m; + *tmp++ = ' '; + if (lifetime > 0) + has_dns = 1; + } + } + if (tmp != opt) + (*--tmp) = '\0'; + else + *opt = '\0'; } - (*--tmp) = '\0'; break; case ND_OPT_DNSSL: