Merge pull request #7122 from Icinga/bugfix/evaluatefilter-change-globals

FilterUtility::EvaluateFilter(): ensure not to modify the global namespace
This commit is contained in:
Michael Friedrich 2019-04-16 17:40:20 +02:00 committed by GitHub
commit ab97d606db
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 4 additions and 4 deletions

View File

@ -89,6 +89,8 @@ bool FilterUtility::EvaluateFilter(ScriptFrame& frame, Expression *filter,
ASSERT(frame.Self.IsObjectType<Namespace>()); ASSERT(frame.Self.IsObjectType<Namespace>());
frameNS = frame.Self; frameNS = frame.Self;
ASSERT(frameNS != ScriptGlobal::GetGlobals());
} }
frameNS->Set("obj", target); frameNS->Set("obj", target);
@ -239,9 +241,9 @@ std::vector<Value> FilterUtility::GetFilterTargets(const QueryDescription& qd, c
if (qd.Types.find(type) == qd.Types.end()) if (qd.Types.find(type) == qd.Types.end())
BOOST_THROW_EXCEPTION(std::invalid_argument("Invalid type specified for this query.")); BOOST_THROW_EXCEPTION(std::invalid_argument("Invalid type specified for this query."));
ScriptFrame frame(true);
frame.Sandboxed = true;
Namespace::Ptr frameNS = new Namespace(); Namespace::Ptr frameNS = new Namespace();
ScriptFrame frame(true, frameNS);
frame.Sandboxed = true;
if (query->Contains("filter")) { if (query->Contains("filter")) {
String filter = HttpUtility::GetLastParameter(query, "filter"); String filter = HttpUtility::GetLastParameter(query, "filter");
@ -255,8 +257,6 @@ std::vector<Value> FilterUtility::GetFilterTargets(const QueryDescription& qd, c
} }
} }
frame.Self = frameNS;
provider->FindTargets(type, std::bind(&FilteredAddTarget, provider->FindTargets(type, std::bind(&FilteredAddTarget,
std::ref(permissionFrame), permissionFilter, std::ref(permissionFrame), permissionFilter,
std::ref(frame), &*ufilter, std::ref(result), variableName, _1)); std::ref(frame), &*ufilter, std::ref(result), variableName, _1));