-
Notifications
You must be signed in to change notification settings - Fork 584
Disallow nested config objects #8655
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
|
@cla-bot check |
First impression when looking at the diff: the condition is detected quite late. I think this situation is comparable to how icinga2/lib/config/config_parser.yy Lines 502 to 503 in f679ea4
Similarly, it should be possible there to add some inside |
That's for a reason:
|
Interesting point. Is that something that is supposed/expected to work? Potential alternative would be to restrict |
Why not?
|
Well, it's all about the language design and specification. https://icinga.com/docs/icinga-2/latest/doc/17-language-reference/ makes no statements about where After all, we could also ask why not allow something like this:
So the question is: is anyone aware that you can register new (global) objects in functions? Is anyone using it? Do we want to support it? I'm currently looking at this PR due to #9434: unfortunately I'm still waiting for user feedback but given the stack trace, it looks like some unexpected nesting of This kind of explains my motivation behind the idea of restricting the use of Which brings back the question: is there a good reason to actually define objects in a function so that it's worth keeping and supporting this? Or are we better of with disallowing it and having fewer surprises in real world configs? |
You're giving me bad ideas. Your PR still allows the following (you can't use
Do this in many checkables, then the lambdas are evaluated concurrently, still triggering the race condition in #9434:
|
You were right,
gave me
whereas
just worked
until now:
|
I still haven't figured out why |
CommitNewItems() does CreateChildObjects() on a second stack level. |
I've added logging to Anyways, |
lib/config/applyrule.cpp
Outdated
@@ -75,6 +76,8 @@ void ApplyRule::AddRule(const String& sourceType, const String& targetType, cons | |||
const Expression::Ptr& expression, const Expression::Ptr& filter, const String& package, const String& fkvar, | |||
const String& fvvar, const Expression::Ptr& fterm, bool ignoreOnError, const DebugInfo& di, const Dictionary::Ptr& scope) | |||
{ | |||
ActivationContext::AssertOnContext(); | |||
|
|||
m_Rules[sourceType].push_back(ApplyRule(targetType, name, expression, filter, package, fkvar, fvvar, fterm, ignoreOnError, di, scope)); | |||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do this here and not also within ApplyExpression::DoEvaluate()
?
DoEvaluate
evaluates other expressions before (indirectly) calling AddRule
, so when doing something like apply Service f() ...
, this would now still evaluate f()
before telling you that you can't even use apply
there.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Check out this creative use of things crashing with a segfault:
object Host "h" {
enable_active_checks = false
check_command = "dummy"
var h = this
vars.dummy_text = () use (h) => {
apply Service h.vars.dummy_text() {
assign where false
}
}
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do this here and not also within
ApplyExpression::DoEvaluate()
?
DoEvaluate
evaluates other expressions ...
As I said in the second commit's message:
Prevent apply rule creation outside of an activation context
just like object creation.
Rationale: make the behaviours as similar as possible.
Check out this creative use of things crashing with a segfault:
C'mon. That trick is old.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So you're saying with object
instead of apply
in my example, it would still crash? I think it would be nicer to - in both cases - detect that this is an invalid use of apply
or object
earlier, rather than after starting to evaluate the expression.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Yes.
- C'mon! You're calling a function recursively w/o an exit condition.
51930dc
to
8ddaa73
Compare
8ddaa73
to
911d18b
Compare
just like object creation.
911d18b
to
1c49db3
Compare
fixes #8633