[icinga-checkins] icinga.org: icinga2/feature/livestatus-bygroup-7361: Fix a crash in SocketEvents::OnEvent

git at icinga.org git at icinga.org
Mon Feb 16 11:18:53 CET 2015


Module: icinga2
Branch: feature/livestatus-bygroup-7361
Commit: 3c6ca2957bbcb6c98035408408c0d2ae76a90b68
URL:    https://git.icinga.org/?p=icinga2.git;a=commit;h=3c6ca2957bbcb6c98035408408c0d2ae76a90b68

Author: Gunnar Beutner <gunnar at beutner.name>
Date:   Sun Feb 15 18:50:25 2015 +0100

Fix a crash in SocketEvents::OnEvent

fixes #8446

---

 lib/base/socketevents.cpp |   14 ++++++++++++--
 lib/base/tlsstream.cpp    |    5 +++++
 lib/base/tlsstream.hpp    |    1 +
 3 files changed, 18 insertions(+), 2 deletions(-)

diff --git a/lib/base/socketevents.cpp b/lib/base/socketevents.cpp
index 26c6200..6473185 100644
--- a/lib/base/socketevents.cpp
+++ b/lib/base/socketevents.cpp
@@ -153,11 +153,13 @@ SocketEvents::SocketEvents(const Socket::Ptr& socket)
 
 SocketEvents::~SocketEvents(void)
 {
-	Unregister();
+	ASSERT(m_FD == INVALID_SOCKET);
 }
 
 void SocketEvents::Register(void)
 {
+	ASSERT(m_FD != INVALID_SOCKET);
+
 	SocketEventDescriptor desc;
 	desc.Events = 0;
 	desc.EventInterface = this;
@@ -165,6 +167,8 @@ void SocketEvents::Register(void)
 	{
 		boost::mutex::scoped_lock lock(l_SocketIOMutex);
 
+		ASSERT(l_SocketIOSockets.find(m_FD) == l_SocketIOSockets.end());
+
 		l_SocketIOSockets[m_FD] = desc;
 	}
 
@@ -173,17 +177,23 @@ void SocketEvents::Register(void)
 
 void SocketEvents::Unregister(void)
 {
+	if (m_FD == INVALID_SOCKET)
+		return;
+
 	{
 		boost::mutex::scoped_lock lock(l_SocketIOMutex);
 
 		l_SocketIOSockets.erase(m_FD);
+		m_FD = INVALID_SOCKET;
 	}
 
-	/* There's no need to wake up the I/O thread here. */
+	WakeUpThread();
 }
 
 void SocketEvents::ChangeEvents(int events)
 {
+	ASSERT(m_FD != INVALID_SOCKET);
+
 	{
 		boost::mutex::scoped_lock lock(l_SocketIOMutex);
 
diff --git a/lib/base/tlsstream.cpp b/lib/base/tlsstream.cpp
index 0eb9878..9057d90 100644
--- a/lib/base/tlsstream.cpp
+++ b/lib/base/tlsstream.cpp
@@ -77,6 +77,11 @@ TlsStream::TlsStream(const Socket::Ptr& socket, ConnectionRole role, const boost
 		SSL_set_connect_state(m_SSL.get());
 }
 
+TlsStream::~TlsStream(void)
+{
+	SocketEvents::Unregister();
+}
+
 int TlsStream::ValidateCertificate(int preverify_ok, X509_STORE_CTX *ctx)
 {
 	SSL *ssl = static_cast<SSL *>(X509_STORE_CTX_get_ex_data(ctx, SSL_get_ex_data_X509_STORE_CTX_idx()));
diff --git a/lib/base/tlsstream.hpp b/lib/base/tlsstream.hpp
index e885a81..10c4c58 100644
--- a/lib/base/tlsstream.hpp
+++ b/lib/base/tlsstream.hpp
@@ -50,6 +50,7 @@ public:
 	DECLARE_PTR_TYPEDEFS(TlsStream);
 
 	TlsStream(const Socket::Ptr& socket, ConnectionRole role, const boost::shared_ptr<SSL_CTX>& sslContext);
+	~TlsStream(void);
 
 	boost::shared_ptr<X509> GetClientCertificate(void) const;
 	boost::shared_ptr<X509> GetPeerCertificate(void) const;



More information about the icinga-checkins mailing list