Bladeren bron

HPCC-17837 Coverity warning calling timedout without checking return

Signed-off-by: Mark Kelly <mark.kelly@lexisnexisrisk.com>
Mark Kelly 8 jaren geleden
bovenliggende
commit
99823b7897
3 gewijzigde bestanden met toevoegingen van 27 en 10 verwijderingen
  1. 20 10
      common/remote/sockfile.cpp
  2. 5 0
      system/jlib/jsocket.cpp
  3. 2 0
      system/jlib/jsocket.hpp

+ 20 - 10
common/remote/sockfile.cpp

@@ -1002,7 +1002,8 @@ class CRemoteBase: public CInterface
             try {
                 if (tm.timemon) {
                     unsigned remaining;
-                    tm.timemon->timedout(&remaining);
+                    if (tm.timemon->timedout(&remaining))
+                        throwJSocketException(JSOCKERR_connection_failed);
                     socket.setown(ISocket::connect_timeout(ep,remaining));
                 }
                 else
@@ -1057,18 +1058,27 @@ class CRemoteBase: public CInterface
                 else
                     break;
             }
+            bool timeExpired = false;
             unsigned sleeptime = getRandom()%3000+1000;
-            if (tm.timemon) {
+            if (tm.timemon)
+            {
                 unsigned remaining;
-                tm.timemon->timedout(&remaining);
-                if (remaining/2<sleeptime)
-                    sleeptime = remaining/2;
+                if (tm.timemon->timedout(&remaining))
+                    timeExpired = true;
+                else
+                {
+                    if (remaining/2<sleeptime)
+                        sleeptime = remaining/2;
+                }
+            }
+            if (!timeExpired)
+            {
+                Sleep(sleeptime);       // prevent multiple retries beating
+                if (ep.port == securitySettings.daFileSrvSSLPort)
+                    PROGLOG("Retrying SECURE connect");
+                else
+                    PROGLOG("Retrying connect");
             }
-            Sleep(sleeptime);       // prevent multiple retries beating
-            if (ep.port == securitySettings.daFileSrvSSLPort)
-                PROGLOG("Retrying SECURE connect");
-            else
-                PROGLOG("Retrying connect");
         }
         if (ConnectionTable)
             ConnectionTable->addLink(ep,socket);

+ 5 - 0
system/jlib/jsocket.cpp

@@ -674,6 +674,11 @@ typedef union {
 #define INET6_ADDRSTRLEN 65
 #endif
 
+extern jlib_decl void throwJSocketException(int jsockErr)
+{
+    THROWJSOCKEXCEPTION2(jsockErr);
+}
+
 inline void LogErr(unsigned err,unsigned ref,const char *info,unsigned lineno,const char *tracename)
 {
     if (err)

+ 2 - 0
system/jlib/jsocket.hpp

@@ -622,5 +622,7 @@ extern jlib_decl int wait_write_multiple(UnsignedArray  &socks,     //IN   socke
                                         unsigned timeoutMS,         //IN   timeout
                                         UnsignedArray  &readySocks);//OUT  sockets ready to be written
 
+extern jlib_decl void throwJSocketException(int jsockErr);
+
 #endif