[PATCH resend] ws2_32: Check WSAStartup before using WSAHton(l|s)
Signed-off-by: Walter Procyk <minion.procyk(a)gmail.com> --- dlls/ws2_32/socket.c | 17 +++++++++-------- dlls/ws2_32/tests/sock.c | 10 ++++++++++ 2 files changed, 19 insertions(+), 8 deletions(-) diff --git a/dlls/ws2_32/socket.c b/dlls/ws2_32/socket.c index 262171ebab0..1d0caab5d1c 100644 --- a/dlls/ws2_32/socket.c +++ b/dlls/ws2_32/socket.c @@ -4253,13 +4253,14 @@ WS_u_short WINAPI WS_htons(WS_u_short hostshort) /*********************************************************************** * WSAHtonl (WS2_32.46) - * From MSDN description of error codes, this function should also - * check if WinSock has been initialized and the socket is a valid - * socket. But why? This function only translates a host byte order - * u_long into a network byte order u_long... */ int WINAPI WSAHtonl(SOCKET s, WS_u_long hostlong, WS_u_long *lpnetlong) { + if(!num_startup){ + SetLastError(WSANOTINITIALISED); + return SOCKET_ERROR; + } + if (lpnetlong) { *lpnetlong = htonl(hostlong); @@ -4271,13 +4272,13 @@ int WINAPI WSAHtonl(SOCKET s, WS_u_long hostlong, WS_u_long *lpnetlong) /*********************************************************************** * WSAHtons (WS2_32.47) - * From MSDN description of error codes, this function should also - * check if WinSock has been initialized and the socket is a valid - * socket. But why? This function only translates a host byte order - * u_short into a network byte order u_short... */ int WINAPI WSAHtons(SOCKET s, WS_u_short hostshort, WS_u_short *lpnetshort) { + if(!num_startup){ + SetLastError(WSANOTINITIALISED); + return SOCKET_ERROR; + } if (lpnetshort) { diff --git a/dlls/ws2_32/tests/sock.c b/dlls/ws2_32/tests/sock.c index 5a1a271b099..90987532b03 100644 --- a/dlls/ws2_32/tests/sock.c +++ b/dlls/ws2_32/tests/sock.c @@ -1089,6 +1089,16 @@ static void test_WithoutWSAStartup(void) ok(gethostbyname("localhost") == NULL, "gethostbyname() succeeded unexpectedly\n"); err = WSAGetLastError(); ok(err == WSANOTINITIALISED, "Expected 10093, received %d\n", err); + + WSASetLastError(0xdeadbeef); + ok(SOCKET_ERROR == WSAHtonl(0, 0, 0), "Expected SOCKET_ERROR, but was successful\n"); + err = WSAGetLastError(); + ok(err == WSANOTINITIALISED, "Expected 10093, received %d\n", err); + + WSASetLastError(0xdeadbeef); + ok(SOCKET_ERROR == WSAHtons(0, 0, 0), "Expected SOCKET_ERROR, but was successful\n"); + err = WSAGetLastError(); + ok(err == WSANOTINITIALISED, "Expected 10093, received %d\n", err); } static void test_WithWSAStartup(void) -- 2.30.2
participants (1)
-
Walter Procyk