diff options
author | brain <brain@e03df62e-2008-0410-955e-edbf42e46eb7> | 2007-07-27 16:50:53 +0000 |
---|---|---|
committer | brain <brain@e03df62e-2008-0410-955e-edbf42e46eb7> | 2007-07-27 16:50:53 +0000 |
commit | ac3af8b61e9601d9585510d99891e993eb3a2722 (patch) | |
tree | 531ae6aab2e4122cbc5d03b0580876ecd68d77c9 | |
parent | 27d4ea0d970ed95cf21acedf72a08611ea082d72 (diff) |
Some smart tricks to eliminate win32 ifdefs that are creeping into portable files
git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@7589 e03df62e-2008-0410-955e-edbf42e46eb7
-rw-r--r-- | include/socketengine.h | 6 | ||||
-rw-r--r-- | src/inspsocket.cpp | 2 | ||||
-rw-r--r-- | src/socketengine.cpp | 9 | ||||
-rw-r--r-- | src/socketengine_iocp.cpp | 11 | ||||
-rw-r--r-- | src/users.cpp | 6 |
5 files changed, 29 insertions, 5 deletions
diff --git a/include/socketengine.h b/include/socketengine.h index ce701beff..112496656 100644 --- a/include/socketengine.h +++ b/include/socketengine.h @@ -290,6 +290,12 @@ public: * @return The socket engine name */ virtual std::string GetName(); + + /** Returns true if the file descriptors in the + * given event handler are within sensible ranges + * which can be handled by the socket engine. + */ + bool BoundsCheckFd(EventHandler* eh); }; #endif diff --git a/src/inspsocket.cpp b/src/inspsocket.cpp index edb58a05c..3eddb6f62 100644 --- a/src/inspsocket.cpp +++ b/src/inspsocket.cpp @@ -378,6 +378,8 @@ std::string InspSocket::GetIP() char* InspSocket::Read() { + if (Instance->SE->BoundsCheckFd(this)) + return NULL; #ifdef WINDOWS if ((fd < 0) || (m_internalFd > MAX_DESCRIPTORS)) #else diff --git a/src/socketengine.cpp b/src/socketengine.cpp index 48f7e11bf..28ba8c252 100644 --- a/src/socketengine.cpp +++ b/src/socketengine.cpp @@ -91,3 +91,12 @@ std::string SocketEngine::GetName() return "misconfigured"; } +bool SocketEngine::BoundsCheckFd(EventHandler* eh) +{ + if (!eh) + return false; + if ((eh->GetFd() < 0) || (eh->GetFd() > MAX_DESCRIPTORS)) + return false; + return true; +} + diff --git a/src/socketengine_iocp.cpp b/src/socketengine_iocp.cpp index c61b44062..dad8b8a0a 100644 --- a/src/socketengine_iocp.cpp +++ b/src/socketengine_iocp.cpp @@ -420,6 +420,17 @@ bool IOCPEngine::HasFd(int fd) return (GetRef(fd) != 0); } +bool IOCPEngine::BoundsCheckFd(EventHandler* eh) +{ + if (!eh) + return false; + if ((eh->m_internalFd < 0) || (eh->m_internalFd > MAX_DESCRIPTORS)) + return false; + if ((eh->GetFd() < 0) || (eh->GetFd() > MAX_DESCRIPTORS)) + return false; + return true; +} + EventHandler * IOCPEngine::GetIntRef(int fd) { if(fd < 0 || fd > MAX_DESCRIPTORS) diff --git a/src/users.cpp b/src/users.cpp index 12742bbc9..efaffd2dd 100644 --- a/src/users.cpp +++ b/src/users.cpp @@ -1354,11 +1354,7 @@ const char* userrec::GetIPString(char* buf) */ void userrec::Write(std::string text) { -#ifdef WINDOWS - if ((this->fd < 0) || (this->m_internalFd > MAX_DESCRIPTORS)) -#else - if ((this->fd < 0) || (this->fd > MAX_DESCRIPTORS)) -#endif + if (ServerInstance->SE->BoundsCheckFd(this)) return; try |