Shared: Apply ShowProvenance in InlineFlowTest.qll

This commit is contained in:
Tom Hvitved
2024-08-07 13:14:58 +02:00
parent 0dfdee775b
commit f83df76928
9 changed files with 74 additions and 5 deletions

View File

@@ -38,6 +38,9 @@ signature module InputSig<LocationSig Location, DF::InputSig<Location> DataFlowL
bindingset[src, sink]
string getArgString(DataFlowLang::Node src, DataFlowLang::Node sink);
/** Holds if the given extension tuple `madId` should pretty-print as `model`. */
predicate interpretModelForTest(QlBuiltins::ExtensionId madId, string model);
}
module InlineFlowTestMake<
@@ -51,6 +54,8 @@ module InlineFlowTestMake<
private module InlineExpectationsTest = IET::Make<Test>;
private import ProvenancePathGraph
module DefaultFlowConfig implements DataFlow::ConfigSig {
predicate isSource(DataFlowLang::Node source) { Impl::defaultSource(source) }
@@ -66,13 +71,33 @@ module InlineFlowTestMake<
bindingset[src, sink]
signature string getArgStringSig(DataFlowLang::Node src, DataFlowLang::Node sink);
private module DataFlowGlobal<DataFlow::ConfigSig Config> {
private import DataFlow::Global<Config> as G
import G
module PathGraphNoInterpretModel = G::PathGraph;
module PathGraph =
ShowProvenance<Impl::interpretModelForTest/2, PathNode, PathGraphNoInterpretModel>;
}
private module TaintTrackingGlobal<DataFlow::ConfigSig Config> {
private import TaintTracking::Global<Config> as G
import G
module PathGraphNoInterpretModel = G::PathGraph;
module PathGraph =
ShowProvenance<Impl::interpretModelForTest/2, PathNode, PathGraphNoInterpretModel>;
}
module FlowTestArgString<
DataFlow::ConfigSig ValueFlowConfig, DataFlow::ConfigSig TaintFlowConfig,
getArgStringSig/2 getArgString>
{
module ValueFlow = DataFlow::Global<ValueFlowConfig>;
module ValueFlow = DataFlowGlobal<ValueFlowConfig>;
module TaintFlow = TaintTracking::Global<TaintFlowConfig>;
module TaintFlow = TaintTrackingGlobal<TaintFlowConfig>;
private predicate hasLocationInfo(DataFlowLang::Node node, Test::Location location) {
exists(string filepath, int startline, int startcolumn, int endline, int endcolumn |
@@ -104,7 +129,11 @@ module InlineFlowTestMake<
}
import InlineExpectationsTest::MakeTest<InlineTest>
import DataFlow::MergePathGraph<ValueFlow::PathNode, TaintFlow::PathNode, ValueFlow::PathGraph, TaintFlow::PathGraph>
private import DataFlow::MergePathGraph<ValueFlow::PathNode, TaintFlow::PathNode, ValueFlow::PathGraphNoInterpretModel, TaintFlow::PathGraphNoInterpretModel> as Merged
import Merged
module PathGraph =
ShowProvenance<Impl::interpretModelForTest/2, Merged::PathNode, Merged::PathGraph>;
predicate flowPath(PathNode source, PathNode sink) {
ValueFlow::flowPath(source.asPathNode1(), sink.asPathNode1()) or

View File

@@ -65,13 +65,13 @@ private module TranslateModels<
/** Transforms a `PathGraph` by printing the provenance information. */
module ShowProvenance<
interpretModelForTestSig/2 interpretModelForTest, PathNodeSig PathNode,
DF::PathGraphSig<PathNode> PathGraph>
DF::PathGraphSig<PathNode> PathGraph> implements DF::PathGraphSig<PathNode>
{
private predicate provenance(string model) { PathGraph::edges(_, _, _, model) }
private module Models = TranslateModels<interpretModelForTest/2, provenance/1>;
query predicate models(int r, string model) { Models::models(r, model) }
additional query predicate models(int r, string model) { Models::models(r, model) }
query predicate edges(PathNode a, PathNode b, string key, string val) {
exists(string model |