I experienced a buffer overrun exception in c-ares on Windows and
tracked it down to be an error in the calculation of the 'left' variable
in get_iphlpapi_dns_info().
I changed the variable type of 'left' to a _signed_ type because of the
subtraction arithmetic; not sure if a long is the best choice
{
const size_t ipv4_size = INET_ADDRSTRLEN + 1; /* +1 for ',' at end */
const size_t ipv6_size = INET6_ADDRSTRLEN + 12; /* +12 for "%0123456789," at end */
- size_t left = ret_size;
+ long left = ret_size;
char *ret = ret_buf;
int count = 0;
ret[ stringlen ] = ',';
ret[ stringlen + 1 ] = '\0';
ret += stringlen + 1;
- left -= ret - ret_buf;
+ left -= stringlen + 1;
++count;
}
else if( pGenericAddr->sa_family == AF_INET6 && left > ipv6_size )
ret[ stringlen ] = ',';
ret[ stringlen + 1 ] = '\0';
ret += stringlen + 1;
- left -= ret - ret_buf;
+ left -= stringlen + 1;
++count;
/* NB on Windows this also returns stuff in the fec0::/10 range,