Fix segfault with zones without endpoints on config compile.

Fixes #6425
This commit is contained in:
Michael Friedrich 2014-06-06 13:30:06 +02:00
parent addad4ae9c
commit 78e4b28006
2 changed files with 18 additions and 2 deletions

View File

@ -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."));

View File

@ -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;
}