mirror of
https://frontier.innolan.net/rainlance/c-ares.git
synced 2025-10-06 13:29:42 +00:00
get_iphlpapi_dns_info: fix buffer overrun
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
This commit is contained in:
committed by
Daniel Stenberg
parent
90a150f045
commit
73dc26a9fc
@ -612,7 +612,7 @@ static int get_iphlpapi_dns_info (char *ret_buf, size_t ret_size)
|
||||
{
|
||||
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;
|
||||
|
||||
@ -687,7 +687,7 @@ static int get_iphlpapi_dns_info (char *ret_buf, size_t ret_size)
|
||||
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 )
|
||||
@ -702,7 +702,7 @@ static int get_iphlpapi_dns_info (char *ret_buf, size_t ret_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,
|
||||
|
Reference in New Issue
Block a user