Skip to content

Commit 1c49db3

Browse files
committed
Prevent apply rule creation outside of an activation context
just like object creation.
1 parent 924068c commit 1c49db3

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

lib/config/activationcontext.hpp

+6
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,12 @@ class ActivationContext final : public Object
1818

1919
static ActivationContext::Ptr GetCurrentContext();
2020

21+
static inline
22+
void AssertOnContext()
23+
{
24+
GetCurrentContext();
25+
}
26+
2127
private:
2228
static void PushContext(const ActivationContext::Ptr& context);
2329
static void PopContext();

lib/config/applyrule.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/* Icinga 2 | (c) 2012 Icinga GmbH | GPLv2+ */
22

3+
#include "config/activationcontext.hpp"
34
#include "config/applyrule.hpp"
45
#include "base/logger.hpp"
56
#include <set>
@@ -61,6 +62,8 @@ void ApplyRule::AddRule(const String& sourceType, const String& targetType, cons
6162
const Expression::Ptr& expression, const Expression::Ptr& filter, const String& package, const String& fkvar,
6263
const String& fvvar, const Expression::Ptr& fterm, bool ignoreOnError, const DebugInfo& di, const Dictionary::Ptr& scope)
6364
{
65+
ActivationContext::AssertOnContext();
66+
6467
auto actualTargetType (&targetType);
6568

6669
if (*actualTargetType == "") {

0 commit comments

Comments
 (0)