From 2d6796aac51d8a5963f552b8fa23a2396a987913 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Sun, 25 Sep 2011 17:34:12 +0200 Subject: curl_multi_fdset: avoid FD_SET out of bounds If a socket is larger than FD_SETSIZE, avoid using FD_SET() on the platforms where this is possible. Bug: http://curl.haxx.se/bug/view.cgi?id=3413274 Reported by: Tim Starling --- lib/select.h | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'lib/select.h') diff --git a/lib/select.h b/lib/select.h index d785fb393..56729a3b2 100644 --- a/lib/select.h +++ b/lib/select.h @@ -96,4 +96,20 @@ 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 + unfortunately makes it impossible for us to easily check if they're valid +*/ +#if defined(USE_WINSOCK) || defined(TPF) +#define VALID_SOCK(x) 1 +#define VERIFY_SOCK(x) Curl_nop_stmt +#else +#define VALID_SOCK(s) (((s) >= 0) && ((s) < FD_SETSIZE)) +#define VERIFY_SOCK(x) do { \ + if(!VALID_SOCK(x)) { \ + SET_SOCKERRNO(EINVAL); \ + return -1; \ + } \ +} WHILE_FALSE +#endif + #endif /* __SELECT_H */ -- cgit v1.2.1