[icinga-checkins] icinga.org: icinga2/next: Fix segfault with zones without endpoints on config compile.

git at icinga.org git at icinga.org
Fri Jun 6 13:30:25 CEST 2014


Module: icinga2
Branch: next
Commit: 78e4b28006f01a8be819577bfc3aaa3bb20f60fe
URL:    https://git.icinga.org/?p=icinga2.git;a=commit;h=78e4b28006f01a8be819577bfc3aaa3bb20f60fe

Author: Michael Friedrich <michael.friedrich at netways.de>
Date:   Fri Jun  6 13:30:06 2014 +0200

Fix segfault with zones without endpoints on config compile.

Fixes #6425

---

 lib/remote/endpoint.cpp |    3 +++
 lib/remote/zone.cpp     |   17 +++++++++++++++--
 2 files changed, 18 insertions(+), 2 deletions(-)

diff --git a/lib/remote/endpoint.cpp b/lib/remote/endpoint.cpp
index eb50fce..b34740f 100644
--- a/lib/remote/endpoint.cpp
+++ b/lib/remote/endpoint.cpp
@@ -40,6 +40,9 @@ void Endpoint::OnConfigLoaded(void)
 	BOOST_FOREACH(const Zone::Ptr& zone, DynamicType::GetObjects<Zone>()) {
 		const std::set<Endpoint::Ptr> members = zone->GetEndpoints();
 
+		if (members.empty())
+			continue;
+
 		if (members.find(GetSelf()) != members.end()) {
 			if (m_Zone)
 				BOOST_THROW_EXCEPTION(std::runtime_error("Endpoint '" + GetName() + "' is in more than one zone."));
diff --git a/lib/remote/zone.cpp b/lib/remote/zone.cpp
index ac73307..2dbe706 100644
--- a/lib/remote/zone.cpp
+++ b/lib/remote/zone.cpp
@@ -18,6 +18,7 @@
  ******************************************************************************/
 
 #include "remote/zone.hpp"
+#include "base/objectlock.hpp"
 #include <boost/foreach.hpp>
 
 using namespace icinga;
@@ -33,8 +34,20 @@ std::set<Endpoint::Ptr> Zone::GetEndpoints(void) const
 {
 	std::set<Endpoint::Ptr> result;
 
-	BOOST_FOREACH(const String& endpoint, GetEndpointsRaw())
-		result.insert(Endpoint::GetByName(endpoint));
+	Array::Ptr endpoints = GetEndpointsRaw();
+
+	if (endpoints) {
+		ObjectLock olock(endpoints);
+
+		BOOST_FOREACH(const String& name, endpoints) {
+			Endpoint::Ptr endpoint = Endpoint::GetByName(name);
+
+			if (!endpoint)
+				continue;
+
+			result.insert(endpoint);
+		}
+	}
 
 	return result;
 }



More information about the icinga-checkins mailing list