Avoid sillyness if not a valid IPv6 address
diff --git a/ipv6rs.c b/ipv6rs.c
index 0ca5b17..f48d01c 100644
--- a/ipv6rs.c
+++ b/ipv6rs.c
@@ -378,7 +378,7 @@
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 @@
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: