From d4595a9a265ce6fa0c486d0194550c9459c7f99e Mon Sep 17 00:00:00 2001 From: Paul Gofman Date: Thu, 10 Mar 2022 12:40:53 +0300 Subject: [PATCH] ws2_32: Manage shorter length for IP_PKTINFO. Signed-off-by: Paul Gofman Signed-off-by: Zebediah Figura Signed-off-by: Alexandre Julliard --- dlls/ws2_32/socket.c | 11 +++++++++++ dlls/ws2_32/tests/sock.c | 1 + 2 files changed, 12 insertions(+) diff --git a/dlls/ws2_32/socket.c b/dlls/ws2_32/socket.c index 80665ff57a4..1ed0418692d 100644 --- a/dlls/ws2_32/socket.c +++ b/dlls/ws2_32/socket.c @@ -1761,6 +1761,12 @@ int WINAPI getsockopt( SOCKET s, int level, int optname, char *optval, int *optl return server_getsockopt( s, IOCTL_AFD_WINE_GET_IP_OPTIONS, optval, optlen ); case IP_PKTINFO: + if (*optlen < sizeof(DWORD) || !optval) + { + *optlen = 0; + SetLastError( WSAEFAULT ); + return SOCKET_ERROR; + } return server_getsockopt( s, IOCTL_AFD_WINE_GET_IP_PKTINFO, optval, optlen ); case IP_RECVTOS: @@ -3072,6 +3078,11 @@ int WINAPI setsockopt( SOCKET s, int level, int optname, const char *optval, int return server_setsockopt( s, IOCTL_AFD_WINE_SET_IP_OPTIONS, optval, optlen ); case IP_PKTINFO: + if (optlen < sizeof(DWORD) || !optval) + { + SetLastError( WSAEFAULT ); + return SOCKET_ERROR; + } return server_setsockopt( s, IOCTL_AFD_WINE_SET_IP_PKTINFO, optval, optlen ); case IP_RECVTOS: diff --git a/dlls/ws2_32/tests/sock.c b/dlls/ws2_32/tests/sock.c index afdfc68905b..3bde96b722d 100644 --- a/dlls/ws2_32/tests/sock.c +++ b/dlls/ws2_32/tests/sock.c @@ -1184,6 +1184,7 @@ static void test_set_getsockopt(void) {AF_INET, SOCK_STREAM, IPPROTO_TCP, TCP_NODELAY, TRUE, {1, 1, 1}, {0}, TRUE}, {AF_INET, SOCK_DGRAM, IPPROTO_IP, IP_MULTICAST_LOOP, TRUE, {1, 1, 4}, {0}, TRUE, TRUE}, {AF_INET, SOCK_DGRAM, IPPROTO_IP, IP_MULTICAST_TTL, TRUE, {1, 1, 4}, {0}, FALSE}, + {AF_INET, SOCK_DGRAM, IPPROTO_IP, IP_PKTINFO, FALSE, {0, 0, 4}, {0}, TRUE, TRUE}, {AF_INET, SOCK_DGRAM, IPPROTO_IP, IP_TOS, TRUE, {1, 1, 4}, {0}, FALSE}, {AF_INET, SOCK_DGRAM, IPPROTO_IP, IP_TTL, TRUE, {1, 1, 4}, {0}, FALSE}, };