iphlpapi: Honor sa_len when reading AF_INET addresses.

Signed-off-by: Stefan Dösinger <stefan@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Stefan Dösinger 2020-04-12 14:24:57 +02:00 committed by Alexandre Julliard
parent 4932eec313
commit f3b64f950f
1 changed files with 26 additions and 24 deletions

View File

@ -1548,17 +1548,20 @@ DWORD WINAPI AllocateAndGetIpForwardTableFromStack(PMIB_IPFORWARDTABLE *ppIpForw
ADVANCE (addrPtr, sa); ADVANCE (addrPtr, sa);
/* default routes are encoded by length-zero sockaddr */
if (sa->sa_len == 0) {
addr = 0;
}else {
/* Apple's netstat prints the netmask together with the destination /* Apple's netstat prints the netmask together with the destination
* and only looks at the destination's address family. The netmask's * and only looks at the destination's address family. The netmask's
* sa_family sometimes contains the non-existent value 0xff. */ * sa_family sometimes contains the non-existent value 0xff. */
switch(i == RTA_NETMASK ? dst_family : sa->sa_family) { switch(i == RTA_NETMASK ? dst_family : sa->sa_family) {
case AF_INET: { case AF_INET: {
struct sockaddr_in *sin = (struct sockaddr_in *)sa; /* Netmasks (and possibly other addresses) have only enough size
addr = sin->sin_addr.s_addr; * to represent the non-zero bits, e.g. a netmask of 255.0.0.0 has
* 5 bytes (1 sa_len, 1 sa_family, 2 sa_port and 1 for the first
* byte of sin_addr). Due to the alignment constraint we can de
* facto read the full 4 bytes of sin_addr (except for the case of
* netmask 0). Don't assume though that the extra bytes are zeroed. */
struct sockaddr_in sin = {0};
memcpy(&sin, sa, sa->sa_len);
addr = sin.sin_addr.s_addr;
break; break;
} }
#ifdef AF_LINK #ifdef AF_LINK
@ -1575,7 +1578,6 @@ DWORD WINAPI AllocateAndGetIpForwardTableFromStack(PMIB_IPFORWARDTABLE *ppIpForw
WARN ("Received unsupported sockaddr family 0x%x\n", sa->sa_family); WARN ("Received unsupported sockaddr family 0x%x\n", sa->sa_family);
addr = 0; addr = 0;
} }
}
switch (i) switch (i)
{ {