Avoid sillyness if not a valid IPv6 address

This commit is contained in:
Roy Marples 2012-11-24 20:35:53 +00:00
parent c2e168a8c1
commit b2e8d8da6a
2 changed files with 30 additions and 12 deletions

10
dhcp.c
View File

@ -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]);

View File

@ -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: