diff --git a/das-dn/third_party/AdsLib/Sockets.cpp b/das-dn/third_party/AdsLib/Sockets.cpp index b8268e1d..d5c86012 100644 --- a/das-dn/third_party/AdsLib/Sockets.cpp +++ b/das-dn/third_party/AdsLib/Sockets.cpp @@ -240,9 +240,12 @@ bool Socket::Select(timeval* timeout) { /* prepare socket set for select() */ if (!IsValid()) { - LOG_ERROR("Socket is invalid: " << std::dec << m_Socket); return false; } + if (m_Socket < 0 || m_Socket >= FD_SETSIZE) { + LOG_ERROR("received a non valid socket (" << m_Socket << "), unable to add to the set"); + return false; + } fd_set readSockets; FD_ZERO(&readSockets); FD_SET(m_Socket, &readSockets); @@ -251,6 +254,7 @@ bool Socket::Select(timeval* timeout) const int state = NATIVE_SELECT(m_Socket + 1, &readSockets, nullptr, nullptr, timeout); if (0 == state) { LOG_ERROR("Socket select() timeout."); + return false; //throw TimeoutEx("select() timeout"); } @@ -258,6 +262,7 @@ bool Socket::Select(timeval* timeout) if (m_LastError == WSAENOTSOCK) { //throw std::runtime_error("connection closed"); Shutdown(); + return false; } /* and check if socket was correct */ @@ -266,7 +271,11 @@ bool Socket::Select(timeval* timeout) return false; } - if(!FD_ISSET(m_Socket, &readSockets)) + if (m_Socket < 0 || m_Socket >= FD_SETSIZE) { + LOG_ERROR("received a non valid socket (" << m_Socket << "), unable to add to the set"); + return false; + } + if (!FD_ISSET(m_Socket, &readSockets)) { return false; }