From facf3ecba903dd10c85321f91e6c10a89dc30ea1 Mon Sep 17 00:00:00 2001 From: Thomas Faber Date: Sat, 7 Nov 2015 08:30:00 +0000 Subject: [PATCH] [WS2_32_NEW] - Add missing SEH in getsockopt/setsockopt CORE-10440 svn path=/trunk/; revision=69823 --- reactos/dll/win32/ws2_32_new/CMakeLists.txt | 2 +- reactos/dll/win32/ws2_32_new/inc/ws2_32.h | 1 + reactos/dll/win32/ws2_32_new/src/sockctrl.c | 100 ++++++++++++++------ 3 files changed, 75 insertions(+), 28 deletions(-) diff --git a/reactos/dll/win32/ws2_32_new/CMakeLists.txt b/reactos/dll/win32/ws2_32_new/CMakeLists.txt index 7754c966825..e474f0ec1ea 100644 --- a/reactos/dll/win32/ws2_32_new/CMakeLists.txt +++ b/reactos/dll/win32/ws2_32_new/CMakeLists.txt @@ -51,7 +51,7 @@ add_library(ws2_32_new SHARED ${CMAKE_CURRENT_BINARY_DIR}/ws2_32_new.def) set_module_type(ws2_32_new win32dll) +target_link_libraries(ws2_32_new ${PSEH_LIB}) add_importlibs(ws2_32_new user32 advapi32 dnsapi ws2help msvcrt kernel32 ntdll) add_pch(ws2_32_new inc/ws2_32.h SOURCE) -target_link_libraries(ws2_32_new wine) add_cd_file(TARGET ws2_32_new DESTINATION reactos/system32 FOR all) diff --git a/reactos/dll/win32/ws2_32_new/inc/ws2_32.h b/reactos/dll/win32/ws2_32_new/inc/ws2_32.h index a613e08ccb1..349a9624790 100644 --- a/reactos/dll/win32/ws2_32_new/inc/ws2_32.h +++ b/reactos/dll/win32/ws2_32_new/inc/ws2_32.h @@ -28,6 +28,7 @@ #include #include #include +#include /* Winsock Helper Header */ #include diff --git a/reactos/dll/win32/ws2_32_new/src/sockctrl.c b/reactos/dll/win32/ws2_32_new/src/sockctrl.c index 4b96f8e1ec7..a5c4581fc65 100644 --- a/reactos/dll/win32/ws2_32_new/src/sockctrl.c +++ b/reactos/dll/win32/ws2_32_new/src/sockctrl.c @@ -272,17 +272,29 @@ getsockopt(IN SOCKET s, if ((level == SOL_SOCKET) && (optname == SO_OPENTYPE)) { /* Validate size */ - if (!(optlen) || (*optlen < sizeof(INT))) + Status = ERROR_SUCCESS; + _SEH2_TRY { - /* Fail */ - SetLastError(WSAEFAULT); - return SOCKET_ERROR; - } + if (!(optlen) || (*optlen < sizeof(INT))) + { + /* Fail */ + Status = SOCKET_ERROR; + SetLastError(WSAEFAULT); + _SEH2_LEAVE; + } - /* Set the open type */ - *optval = (CHAR)Thread->OpenType; - *optlen = sizeof(INT); - return ERROR_SUCCESS; + /* Set the open type */ + *optval = (CHAR)Thread->OpenType; + *optlen = sizeof(INT); + } + _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER) + { + Status = SOCKET_ERROR; + SetLastError(WSAEFAULT); + } + _SEH2_END; + + return Status; } /* Get the Socket Context */ @@ -292,27 +304,42 @@ getsockopt(IN SOCKET s, if ((level == SOL_SOCKET) && (optname == SO_PROTOCOL_INFOA)) { /* Validate size and pointers */ - if(!(optval) || - !(optlen) || - (*optlen < sizeof(WSAPROTOCOL_INFOA))) + ErrorCode = NO_ERROR; + _SEH2_TRY { - /* Set return size */ - *optlen = sizeof(WSAPROTOCOL_INFOA); + if (!(optval) || + !(optlen) || + (*optlen < sizeof(WSAPROTOCOL_INFOA))) + { + /* Set return size and error code */ + *optlen = sizeof(WSAPROTOCOL_INFOA); + ErrorCode = WSAEFAULT; + _SEH2_LEAVE; + } + /* It worked. Save the values */ + OldOptLen = *optlen; + OldOptVal = optval; + + /* Hack them so WSP will know how to deal with it */ + *optlen = sizeof(WSAPROTOCOL_INFOW); + optval = (PCHAR)&ProtocolInfo; + optname = SO_PROTOCOL_INFOW; + } + _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER) + { + ErrorCode = WSAEFAULT; + } + _SEH2_END; + + /* Did we encounter invalid parameters? */ + if (ErrorCode != NO_ERROR) + { /* Dereference the socket and fail */ WsSockDereference(Socket); - SetLastError(WSAEFAULT); + SetLastError(ErrorCode); return SOCKET_ERROR; } - - /* It worked. Save the values */ - OldOptLen = *optlen; - OldOptVal = optval; - - /* Hack them so WSP will know how to deal with it */ - *optlen = sizeof(WSAPROTOCOL_INFOW); - optval = (PCHAR)&ProtocolInfo; - optname = SO_PROTOCOL_INFOW; } /* Make the call */ @@ -338,7 +365,15 @@ getsockopt(IN SOCKET s, OldOptVal); /* Return the length */ - *optlen = OldOptLen; + _SEH2_TRY + { + *optlen = OldOptLen; + } + _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER) + { + ErrorCode = WSAEFAULT; + } + _SEH2_END; /* Return success if this worked */ if (ErrorCode == ERROR_SUCCESS) return Status; @@ -392,8 +427,19 @@ setsockopt(IN SOCKET s, } /* Set the open type */ - Thread->OpenType = *optval; - return ERROR_SUCCESS; + Status = ERROR_SUCCESS; + _SEH2_TRY + { + Thread->OpenType = *optval; + } + _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER) + { + Status = SOCKET_ERROR; + SetLastError(WSAEFAULT); + } + _SEH2_END; + + return Status; } /* Get the Socket Context */