]> granicus.if.org Git - icinga2/commitdiff
Properly deal with closed TLS streams
authorGunnar Beutner <gunnar.beutner@netways.de>
Tue, 9 Sep 2014 13:28:55 +0000 (15:28 +0200)
committerGunnar Beutner <gunnar.beutner@netways.de>
Tue, 9 Sep 2014 13:28:55 +0000 (15:28 +0200)
fixes #6892

lib/base/tlsutility.hpp
lib/remote/apiclient.cpp

index edfdb1c09027e274bd9a9599d729ad044ef023c3..b44b902c2fe2c2a679309280e79129642f29bfe5 100644 (file)
@@ -43,7 +43,7 @@ String I2_BASE_API SHA256(const String& s);
 class I2_BASE_API openssl_error : virtual public std::exception, virtual public boost::exception { };
 
 struct errinfo_openssl_error_;
-typedef boost::error_info<struct errinfo_openssl_error_, int> errinfo_openssl_error;
+typedef boost::error_info<struct errinfo_openssl_error_, unsigned long> errinfo_openssl_error;
 
 inline std::string to_string(const errinfo_openssl_error& e)
 {
index cc0e7a4a43f77d6eda39319b759634e14bd69ff1..9b6117fe2dc606f770fc2ba291656efe86527e09 100644 (file)
@@ -116,7 +116,21 @@ void ApiClient::DisconnectSync(void)
 
 bool ApiClient::ProcessMessage(void)
 {
-       Dictionary::Ptr message = JsonRpc::ReadMessage(m_Stream);
+       Dictionary::Ptr message;
+
+       if (m_Stream->IsEof())
+               return false;
+
+       try {
+               message = JsonRpc::ReadMessage(m_Stream);
+       } catch (const openssl_error& ex) {
+               const unsigned long *pe = boost::get_error_info<errinfo_openssl_error>(ex);
+
+               if (pe && *pe == 0)
+                       return false; /* Connection was closed cleanly */
+
+               throw;
+       }
 
        if (!message)
                return false;