From b2e8d8da6a5f4cc7955c441d68908992c8de3603 Mon Sep 17 00:00:00 2001 From: Roy Marples Date: Sat, 24 Nov 2012 20:35:53 +0000 Subject: [PATCH] Avoid sillyness if not a valid IPv6 address --- dhcp.c | 10 ++++++++-- ipv6rs.c | 32 ++++++++++++++++++++++---------- 2 files changed, 30 insertions(+), 12 deletions(-) diff --git a/dhcp.c b/dhcp.c index 3a157350..b27e0a21 100644 --- a/dhcp.c +++ b/dhcp.c @@ -1311,7 +1311,9 @@ print_option(char *s, ssize_t len, int type, int dl, const uint8_t *data, while (data < e) { if (l) l++; /* space */ - l += ipv6_printaddr(NULL, 0, data, ifname); + dl = ipv6_printaddr(NULL, 0, data, ifname); + if (dl != -1) + l += dl; data += 16; } return l + 1; @@ -1360,7 +1362,11 @@ print_option(char *s, ssize_t len, int type, int dl, const uint8_t *data, l = snprintf(s, len, "%s", inet_ntoa(addr)); data += sizeof(addr.s_addr); } else if (type & IPV6) { - l = ipv6_printaddr(s, len, data, ifname); + dl = ipv6_printaddr(s, len, data, ifname); + if (dl != -1) + l = dl; + else + l = 0; data += 16; } else if (type & BINHEX) { l = snprintf(s, len, "%.2x", data[0]); diff --git a/ipv6rs.c b/ipv6rs.c index fc2c3a4c..d04663ff 100644 --- a/ipv6rs.c +++ b/ipv6rs.c @@ -382,7 +382,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; @@ -654,22 +654,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: