diff --git a/src/lib/ares_init.c b/src/lib/ares_init.c index 6464c241..0fb8393e 100644 --- a/src/lib/ares_init.c +++ b/src/lib/ares_init.c @@ -2064,15 +2064,20 @@ static ares_status_t config_sortlist(struct apattern **sortlist, size_t *nsort, while (*str && *str != ';') { int bits; - char ipbuf[16], ipbufpfx[32]; + char ipbuf[17], ipbufpfx[32]; + size_t len; + /* Find just the IP */ q = str; while (*q && *q != '/' && *q != ';' && !ISSPACE(*q)) q++; - if (q-str >= 16) + + len = (size_t)(q-str); + if (len >= sizeof(ipbuf)-1) return ARES_EBADSTR; - memcpy(ipbuf, str, (size_t)(q-str)); - ipbuf[q-str] = '\0'; + memcpy(ipbuf, str, len); + ipbuf[len] = '\0'; + /* Find the prefix */ if (*q == '/') { @@ -2120,10 +2125,12 @@ static ares_status_t config_sortlist(struct apattern **sortlist, size_t *nsort, { if (ipbufpfx[0]) { - if (q-str >= 16) + len = (size_t)(q-str); + if (len >= sizeof(ipbuf)-1) return ARES_EBADSTR; - memcpy(ipbuf, str, (size_t)(q-str)); - ipbuf[q-str] = '\0'; + memcpy(ipbuf, str, len); + ipbuf[len] = '\0'; + if (ip_addr(ipbuf, q-str, &pat.mask.addr4) != 0) natural_mask(&pat); } diff --git a/src/lib/ares_process.c b/src/lib/ares_process.c index 5d39d5ce..d59637e4 100644 --- a/src/lib/ares_process.c +++ b/src/lib/ares_process.c @@ -1040,7 +1040,7 @@ static int configure_socket(ares_socket_t s, int family, ares_channel channel) } } else if (family == AF_INET6) { - if (memcmp(channel->local_ip6, &ares_in6addr_any, + if (memcmp(channel->local_ip6, ares_in6addr_any._S6_un._S6_u8, sizeof(channel->local_ip6)) != 0) { memset(&local.sa6, 0, sizeof(local.sa6)); local.sa6.sin6_family = AF_INET6;