Skip to content

Commit 18f4b75

Browse files
committed
python: enable summaries from model
This requires a change to the shared interface: Making `getNodeFromPath` public. This because Python is doing its own thing and identifying call-backs.
1 parent cc09715 commit 18f4b75

File tree

2 files changed

+43
-36
lines changed

2 files changed

+43
-36
lines changed

python/ql/lib/semmle/python/dataflow/new/FlowSummary.qll

Lines changed: 34 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -90,39 +90,37 @@ abstract class SummarizedCallable extends LibraryCallable, Impl::Public::Summari
9090
}
9191

9292
class RequiredSummaryComponentStack = Impl::Public::RequiredSummaryComponentStack;
93-
// // This gives access to getNodeFromPath, which is not constrained to `CallNode`s
94-
// // as `resolvedSummaryBase` is.
95-
// private import semmle.python.frameworks.data.internal.ApiGraphModels as AGM
96-
//
97-
// private class SummarizedCallableFromModel extends SummarizedCallable {
98-
// string package;
99-
// string type;
100-
// string path;
101-
// SummarizedCallableFromModel() {
102-
// ModelOutput::relevantSummaryModel(package, type, path, _, _, _) and
103-
// this = package + ";" + type + ";" + path
104-
// }
105-
// override CallCfgNode getACall() {
106-
// exists(API::CallNode base |
107-
// ModelOutput::resolvedSummaryBase(package, type, path, base) and
108-
// result = base.getACall()
109-
// )
110-
// }
111-
// override ArgumentNode getACallback() {
112-
// exists(API::Node base |
113-
// base = AGM::getNodeFromPath(package, type, path) and
114-
// result = base.getAValueReachableFromSource()
115-
// )
116-
// }
117-
// override predicate propagatesFlowExt(string input, string output, boolean preservesValue) {
118-
// exists(string kind |
119-
// ModelOutput::relevantSummaryModel(package, type, path, input, output, kind)
120-
// |
121-
// kind = "value" and
122-
// preservesValue = true
123-
// or
124-
// kind = "taint" and
125-
// preservesValue = false
126-
// )
127-
// }
128-
// }
93+
94+
private class SummarizedCallableFromModel extends SummarizedCallable {
95+
string type;
96+
string path;
97+
98+
SummarizedCallableFromModel() {
99+
ModelOutput::relevantSummaryModel(type, path, _, _, _) and
100+
this = type + ";" + path
101+
}
102+
103+
override CallCfgNode getACall() {
104+
exists(API::CallNode base |
105+
ModelOutput::resolvedSummaryBase(type, path, base) and
106+
result = base.getACall()
107+
)
108+
}
109+
110+
override ArgumentNode getACallback() {
111+
exists(API::Node base |
112+
ModelOutput::resolvedSummaryRefBase(type, path, base) and
113+
result = base.getAValueReachableFromSource()
114+
)
115+
}
116+
117+
override predicate propagatesFlowExt(string input, string output, boolean preservesValue) {
118+
exists(string kind | ModelOutput::relevantSummaryModel(type, path, input, output, kind) |
119+
kind = "value" and
120+
preservesValue = true
121+
or
122+
kind = "taint" and
123+
preservesValue = false
124+
)
125+
}
126+
}

python/ql/lib/semmle/python/frameworks/data/internal/ApiGraphModels.qll

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -643,6 +643,15 @@ module ModelOutput {
643643
baseNode = getInvocationFromPath(type, path)
644644
}
645645

646+
/**
647+
* Holds if a `baseNode` is an invocation identified by the `type,path` part of a summary row.
648+
*/
649+
cached
650+
predicate resolvedSummaryRefBase(string type, string path, API::Node baseNode) {
651+
summaryModel(type, path, _, _, _) and
652+
baseNode = getNodeFromPath(type, path)
653+
}
654+
646655
/**
647656
* Holds if `node` is seen as an instance of `type` due to a type definition
648657
* contributed by a CSV model.

0 commit comments

Comments
 (0)