diff options
author | Marc Hoersken <info@marc-hoersken.de> | 2020-08-03 15:54:08 +0200 |
---|---|---|
committer | Marc Hoersken <info@marc-hoersken.de> | 2020-08-25 11:17:06 +0200 |
commit | 0f7c332f9f36f792a7903760b2a8db45091ed8b6 (patch) | |
tree | 461dc8839b7c72841556959328724de669c89450 | |
parent | 3a9042ea14b302da0606e1b2f46e1eda29f627c3 (diff) | |
download | curl-0f7c332f9f36f792a7903760b2a8db45091ed8b6.tar.gz |
select.h: make socket validation macros test for INVALID_SOCKET
With Winsock the valid range is [0..INVALID_SOCKET-1] according to
https://docs.microsoft.com/en-us/windows/win32/winsock/socket-data-type-2
Reviewed-by: Jay Satiro
Reviewed-by: Marcel Raad
Reviewed-by: Daniel Stenberg
Closes #5760
-rw-r--r-- | lib/select.h | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/lib/select.h b/lib/select.h index 95181f467..c9cc5c2e8 100644 --- a/lib/select.h +++ b/lib/select.h @@ -94,12 +94,23 @@ int tpf_select_libcurl(int maxfds, fd_set* reads, fd_set* writes, fd_set* excepts, struct timeval *tv); #endif -/* Winsock and TPF sockets are not in range [0..FD_SETSIZE-1], which +/* TPF sockets are not in range [0..FD_SETSIZE-1], which unfortunately makes it impossible for us to easily check if they're valid + + With Winsock the valid range is [0..INVALID_SOCKET-1] according to + https://docs.microsoft.com/en-us/windows/win32/winsock/socket-data-type-2 */ -#if defined(USE_WINSOCK) || defined(TPF) +#if defined(TPF) #define VALID_SOCK(x) 1 #define VERIFY_SOCK(x) Curl_nop_stmt +#elif defined(USE_WINSOCK) +#define VALID_SOCK(s) ((s) < INVALID_SOCKET) +#define VERIFY_SOCK(x) do { \ + if(!VALID_SOCK(x)) { \ + SET_SOCKERRNO(WSAEINVAL); \ + return -1; \ + } \ +} while(0) #else #define VALID_SOCK(s) (((s) >= 0) && ((s) < FD_SETSIZE)) #define VERIFY_SOCK(x) do { \ |