[icinga-checkins] icinga.org: icinga2/support/2.5: Improve config validation for arrays of object names

git at icinga.org git at icinga.org
Mon Aug 29 12:22:52 CEST 2016


Module: icinga2
Branch: support/2.5
Commit: 4d4364d9d4fed487a59113923b6f8a4dd01a0ee6
URL:    https://git.icinga.org/?p=icinga2.git;a=commit;h=4d4364d9d4fed487a59113923b6f8a4dd01a0ee6

Author: Gunnar Beutner <gunnar.beutner at netways.de>
Date:   Fri Aug 26 10:36:53 2016 +0200

Improve config validation for arrays of object names

fixes #12556

---

 lib/remote/zone.cpp             |    5 ++++-
 tools/mkclass/classcompiler.cpp |    9 ++++++++-
 2 files changed, 12 insertions(+), 2 deletions(-)

diff --git a/lib/remote/zone.cpp b/lib/remote/zone.cpp
index a9045c3..1db0b95 100644
--- a/lib/remote/zone.cpp
+++ b/lib/remote/zone.cpp
@@ -42,7 +42,10 @@ void Zone::OnAllConfigLoaded(void)
 	if (endpoints) {
 		ObjectLock olock(endpoints);
 		BOOST_FOREACH(const String& endpoint, endpoints) {
-			Endpoint::GetByName(endpoint)->SetCachedZone(this);
+			Endpoint::Ptr ep = Endpoint::GetByName(endpoint);
+
+			if (ep)
+				ep->SetCachedZone(this);
 		}
 	}
 
diff --git a/tools/mkclass/classcompiler.cpp b/tools/mkclass/classcompiler.cpp
index 1e8b1d2..93c413c 100644
--- a/tools/mkclass/classcompiler.cpp
+++ b/tools/mkclass/classcompiler.cpp
@@ -535,7 +535,14 @@ void ClassCompiler::HandleClass(const Klass& klass, const ClassDebugInfo&)
 		std::string ftype = FieldTypeToIcingaName(field, true);
 
 		if (field.Type.IsName) {
-			m_Impl << "\t" << "if (!avalue.IsEmpty() && !utils.ValidateName(\"" << field.Type.TypeName << "\", avalue))" << std::endl
+			m_Impl << "\t" << "if (";
+
+			if (field.Type.ArrayRank > 0)
+				m_Impl << "avalue.IsEmpty() || ";
+			else
+				m_Impl << "!avalue.IsEmpty() && ";
+
+			m_Impl << "!utils.ValidateName(\"" << field.Type.TypeName << "\", avalue))" << std::endl
 			       << "\t\t" << "BOOST_THROW_EXCEPTION(ValidationError(dynamic_cast<ConfigObject *>(this), boost::assign::list_of(\"" << field.Name << "\"), \"Object '\" + avalue + \"' of type '" << field.Type.TypeName
 			       << "' does not exist.\"));" << std::endl;
 		} else if (field.Type.ArrayRank > 0 && (ftype == "Number" || ftype == "Boolean")) {



More information about the icinga-checkins mailing list