From ab2f5061178b91971ef167a0ab2487c9628bcd2b Mon Sep 17 00:00:00 2001 From: drbob Date: Tue, 17 Feb 2015 11:57:08 +0000 Subject: [PATCH] Added extra checks for valid sockfd in cansend / moretoread code git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@7950 b45a01b8-16f6-495d-af2f-9b41ad6348cc --- libretroshare/src/pqi/pqissludp.cc | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/libretroshare/src/pqi/pqissludp.cc b/libretroshare/src/pqi/pqissludp.cc index 834aa6b00..fdc502293 100644 --- a/libretroshare/src/pqi/pqissludp.cc +++ b/libretroshare/src/pqi/pqissludp.cc @@ -552,6 +552,19 @@ bool pqissludp::moretoread(uint32_t usec) { RsStackMutex stack(mSslMtx); /**** LOCKED MUTEX ****/ + // Extra Checks to avoid crashes in v0.6 ... pqithreadstreamer calls this function + // when sockfd = -1 during the shutdown of the thread. + // NB: it should never reach here if bio->isActive() returns false. + // Some mismatch to chase down when we have a chance. + // SAME test is at cansend. + if (sockfd < 0) + { + std::cerr << "pqissludp::moretoread() INVALID sockfd PARAMETER ... bad shutdown?"; + std::cerr << std::endl; + return false; + } + + { std::string out = "pqissludp::moretoread()"; rs_sprintf_append(out, " polling socket (%d)", sockfd); @@ -626,6 +639,18 @@ bool pqissludp::cansend(uint32_t usec) { RsStackMutex stack(mSslMtx); /**** LOCKED MUTEX ****/ + // Extra Checks to avoid crashes in v0.6 ... pqithreadstreamer calls this function + // when sockfd = -1 during the shutdown of the thread. + // NB: it should never reach here if bio->isActive() returns false. + // Some mismatch to chase down when we have a chance. + // SAME test is at can moretoread. + if (sockfd < 0) + { + std::cerr << "pqissludp::cansend() INVALID sockfd PARAMETER ... bad shutdown?"; + std::cerr << std::endl; + return false; + } + if (usec) { std::cerr << "pqissludp::cansend() usec parameter: " << usec;