Преглед изворни кода

HPCC-22156 Secure socket readtms doesn't throw an exception if nothing read

- Add a method in jsocket.hpp to create an IJSOCK_Exception
- Throw an graceful close jsocket exception if min_size>0 and SSL_read's
  return value is less or equal to 0

Signed-off-by: mayx <yanrui.ma@lexisnexisrisk.com>
mayx пре 6 година
родитељ
комит
2c905e46f3
3 измењених фајлова са 16 додато и 15 уклоњено
  1. 5 0
      system/jlib/jsocket.cpp
  2. 1 0
      system/jlib/jsocket.hpp
  3. 10 15
      system/security/securesocket/securesocket.cpp

+ 5 - 0
system/jlib/jsocket.cpp

@@ -697,6 +697,11 @@ extern jlib_decl void throwJSocketException(int jsockErr)
     THROWJSOCKEXCEPTION2(jsockErr);
 }
 
+extern jlib_decl IJSOCK_Exception* createJSocketException(int jsockErr, const char *_msg)
+{
+    return new SocketException(jsockErr, _msg);
+}
+
 inline void LogErr(unsigned err,unsigned ref,const char *info,unsigned lineno,const char *tracename)
 {
     if (err)

+ 1 - 0
system/jlib/jsocket.hpp

@@ -627,6 +627,7 @@ extern jlib_decl int wait_write_multiple(UnsignedArray  &socks,     //IN   socke
                                         UnsignedArray  &readySocks);//OUT  sockets ready to be written
 
 extern jlib_decl void throwJSocketException(int jsockErr);
+extern jlib_decl IJSOCK_Exception* createJSocketException(int jsockErr, const char *_msg);
 
 #endif
 

+ 10 - 15
system/security/securesocket/securesocket.cpp

@@ -773,28 +773,23 @@ void CSecureSocket::readTimeout(void* buf, size32_t min_size, size32_t max_size,
             timeleft = socketTimeRemaining(useSeconds, start, timeout);
         }
 
+        ERR_clear_error();
         rc = SSL_read(m_ssl, (char*)buf + size_read, max_size - size_read);
-        if(rc > 0)
+        if (rc > 0)
         {
             size_read += rc;
         }
         else
         {
             int err = SSL_get_error(m_ssl, rc);
-            // Ignoring SSL_ERROR_SYSCALL because IE prompting user acceptance of the certificate 
-            // causes this error, but is harmless.
-            // Ignoring SSL_ERROR_SYSCALL also seems to ignore the timeout value being exceeded,
-            //    but for persistence at least, treating zero bytes read can be treated as a graceful completion of connection
-            if((err != SSL_ERROR_NONE) && (err != SSL_ERROR_SYSCALL))
-            {
-                if(m_loglevel >= SSLogMax)
-                {
-                    char errbuf[512];
-                    ERR_error_string_n(ERR_get_error(), errbuf, 512);
-                    DBGLOG("Warning: SSL_read error %d - %s", err, errbuf);
-                }
-            }
-            break;
+            char errbuf[512];
+            ERR_error_string_n(err, errbuf, 512);
+            ERR_clear_error();
+            VStringBuffer errmsg("SSL_read error %d - %s", err, errbuf);
+            if (m_loglevel >= SSLogMax)
+                DBGLOG("Warning: %s", errmsg.str());
+            if (min_size > 0)
+                throw createJSocketException(JSOCKERR_graceful_close, errmsg);
         }
     } while (size_read < min_size);
 }