ws2_32: Do not accept sizeof(struct WS_sockaddr_in6_old).

Signed-off-by: Zebediah Figura <zfigura@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Zebediah Figura 2021-07-23 11:39:10 -05:00 committed by Alexandre Julliard
parent 6f3e5090ee
commit 205e2ae036
1 changed files with 11 additions and 16 deletions

View File

@ -1097,14 +1097,14 @@ unsigned int ws_sockaddr_ws2u( const struct WS_sockaddr *wsaddr, int wsaddrlen,
/* Note: Windows has 2 versions of the sockaddr_in6 struct, one with /* Note: Windows has 2 versions of the sockaddr_in6 struct, one with
* scope_id, one without. * scope_id, one without.
*/ */
if (wsaddrlen >= sizeof(struct WS_sockaddr_in6_old)) { if (wsaddrlen >= sizeof(struct WS_sockaddr_in6)) {
uaddrlen = sizeof(struct sockaddr_in6); uaddrlen = sizeof(struct sockaddr_in6);
memset( uaddr, 0, uaddrlen ); memset( uaddr, 0, uaddrlen );
uin6->sin6_family = AF_INET6; uin6->sin6_family = AF_INET6;
uin6->sin6_port = win6->sin6_port; uin6->sin6_port = win6->sin6_port;
uin6->sin6_flowinfo = win6->sin6_flowinfo; uin6->sin6_flowinfo = win6->sin6_flowinfo;
#ifdef HAVE_STRUCT_SOCKADDR_IN6_SIN6_SCOPE_ID #ifdef HAVE_STRUCT_SOCKADDR_IN6_SIN6_SCOPE_ID
if (wsaddrlen >= sizeof(struct WS_sockaddr_in6)) uin6->sin6_scope_id = win6->sin6_scope_id; uin6->sin6_scope_id = win6->sin6_scope_id;
#endif #endif
memcpy(&uin6->sin6_addr,&win6->sin6_addr,16); /* 16 bytes = 128 address bits */ memcpy(&uin6->sin6_addr,&win6->sin6_addr,16); /* 16 bytes = 128 address bits */
break; break;
@ -1299,25 +1299,20 @@ int ws_sockaddr_u2ws(const struct sockaddr *uaddr, struct WS_sockaddr *wsaddr, i
#endif #endif
case AF_INET6: { case AF_INET6: {
const struct sockaddr_in6* uin6 = (const struct sockaddr_in6*)uaddr; const struct sockaddr_in6* uin6 = (const struct sockaddr_in6*)uaddr;
struct WS_sockaddr_in6_old* win6old = (struct WS_sockaddr_in6_old*)wsaddr; struct WS_sockaddr_in6 *win6 = (struct WS_sockaddr_in6 *)wsaddr;
if (*wsaddrlen < sizeof(struct WS_sockaddr_in6_old)) if (*wsaddrlen < sizeof(struct WS_sockaddr_in6))
return -1; return -1;
win6old->sin6_family = WS_AF_INET6; win6->sin6_family = WS_AF_INET6;
win6old->sin6_port = uin6->sin6_port; win6->sin6_port = uin6->sin6_port;
win6old->sin6_flowinfo = uin6->sin6_flowinfo; win6->sin6_flowinfo = uin6->sin6_flowinfo;
memcpy(&win6old->sin6_addr,&uin6->sin6_addr,16); /* 16 bytes = 128 address bits */ memcpy(&win6->sin6_addr, &uin6->sin6_addr, 16); /* 16 bytes = 128 address bits */
#ifdef HAVE_STRUCT_SOCKADDR_IN6_SIN6_SCOPE_ID #ifdef HAVE_STRUCT_SOCKADDR_IN6_SIN6_SCOPE_ID
if (*wsaddrlen >= sizeof(struct WS_sockaddr_in6)) { win6->sin6_scope_id = uin6->sin6_scope_id;
struct WS_sockaddr_in6* win6 = (struct WS_sockaddr_in6*)wsaddr;
win6->sin6_scope_id = uin6->sin6_scope_id;
*wsaddrlen = sizeof(struct WS_sockaddr_in6);
}
else
*wsaddrlen = sizeof(struct WS_sockaddr_in6_old);
#else #else
*wsaddrlen = sizeof(struct WS_sockaddr_in6_old); win6->sin6_scope_id = 0;
#endif #endif
*wsaddrlen = sizeof(struct WS_sockaddr_in6);
return 0; return 0;
} }
case AF_INET: { case AF_INET: {