]> granicus.if.org Git - icinga2/commitdiff
Improve config validation for arrays of object names
authorGunnar Beutner <gunnar.beutner@netways.de>
Fri, 26 Aug 2016 08:36:53 +0000 (10:36 +0200)
committerGunnar Beutner <gunnar.beutner@netways.de>
Fri, 26 Aug 2016 08:36:53 +0000 (10:36 +0200)
fixes #12556

lib/remote/zone.cpp
tools/mkclass/classcompiler.cpp

index d6a6973f9f87ed137a5db68566a134fbf0f5eccb..a72a7a2446b70dd6e33529aa45540805b1f7186a 100644 (file)
@@ -41,7 +41,10 @@ void Zone::OnAllConfigLoaded(void)
        if (endpoints) {
                ObjectLock olock(endpoints);
                for (const String& endpoint : endpoints) {
-                       Endpoint::GetByName(endpoint)->SetCachedZone(this);
+                       Endpoint::Ptr ep = Endpoint::GetByName(endpoint);
+
+                       if (ep)
+                               ep->SetCachedZone(this);
                }
        }
 
index a4a6cc28c9ad969d086a1188e1182e3efe8bcee0..217b56320aa9261599a2dcc2d5cd66ab0c97e1a3 100644 (file)
@@ -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")) {