From: Michael Friedrich Date: Thu, 2 Jul 2015 15:51:52 +0000 (+0200) Subject: Fix config parser ignoring forbidden "ignore" in template definition X-Git-Tag: v2.4.0~550 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=ed3882ba33b0daf321e6bdc9cd256a4b5277bd14;p=icinga2 Fix config parser ignoring forbidden "ignore" in template definition fixes #9535 --- diff --git a/lib/config/config_parser.yy b/lib/config/config_parser.yy index cf1a03a30..de353ada6 100644 --- a/lib/config/config_parser.yy +++ b/lib/config/config_parser.yy @@ -338,6 +338,7 @@ object: { context->m_ObjectAssign.push(true); context->m_SeenAssign.push(false); + context->m_SeenIgnore.push(false); context->m_Assign.push(NULL); context->m_Ignore.push(NULL); } @@ -355,6 +356,9 @@ object: bool seen_assign = context->m_SeenAssign.top(); context->m_SeenAssign.pop(); + bool seen_ignore = context->m_SeenIgnore.top(); + context->m_SeenIgnore.pop(); + Expression *ignore = context->m_Ignore.top(); context->m_Ignore.pop(); @@ -373,6 +377,9 @@ object: filter = new LogicalAndExpression(assign, rex, DebugInfoRange(@2, @5)); } else filter = assign; + } else if (seen_ignore) { + if (!ObjectRule::IsValidSourceType(type)) + BOOST_THROW_EXCEPTION(ScriptError("object rule 'ignore' cannot be used for type '" + type + "'", DebugInfoRange(@2, @4))); } $$ = new ObjectExpression(abstract, type, $4, filter, context->GetZone(), $5, $6, DebugInfoRange(@2, @5)); @@ -478,6 +485,8 @@ lterm: library if ((context->m_Apply.empty() || !context->m_Apply.top()) && (context->m_ObjectAssign.empty() || !context->m_ObjectAssign.top())) BOOST_THROW_EXCEPTION(ScriptError("'ignore' keyword not valid in this context.", @$)); + context->m_SeenIgnore.top() = true; + if (context->m_Ignore.top()) context->m_Ignore.top() = new LogicalOrExpression(context->m_Ignore.top(), $3, @$); else @@ -919,6 +928,7 @@ apply: { context->m_Apply.push(true); context->m_SeenAssign.push(false); + context->m_SeenIgnore.push(false); context->m_Assign.push(NULL); context->m_Ignore.push(NULL); context->m_FKVar.push(""); diff --git a/lib/config/configcompiler.hpp b/lib/config/configcompiler.hpp index 981c44744..f0a429b29 100644 --- a/lib/config/configcompiler.hpp +++ b/lib/config/configcompiler.hpp @@ -126,6 +126,7 @@ public: std::stack m_Apply; std::stack m_ObjectAssign; std::stack m_SeenAssign; + std::stack m_SeenIgnore; std::stack m_Assign; std::stack m_Ignore; std::stack m_FKVar;