]> granicus.if.org Git - icinga2/commitdiff
FilterUtility::EvaluateFilter(): ensure not to modify the global namespace 7122/head
authorAlexander A. Klimov <alexander.klimov@icinga.com>
Tue, 16 Apr 2019 13:53:44 +0000 (15:53 +0200)
committerAlexander A. Klimov <alexander.klimov@icinga.com>
Tue, 16 Apr 2019 13:53:44 +0000 (15:53 +0200)
lib/remote/filterutility.cpp

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