Skip to content

Commit b8dfb01

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 17c9ba9 commit b8dfb01

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
@@ -69,39 +69,37 @@ abstract class SummarizedCallable extends LibraryCallable, Impl::Public::Summari
6969
}
7070

7171
class RequiredSummaryComponentStack = Impl::Public::RequiredSummaryComponentStack;
72-
// // This gives access to getNodeFromPath, which is not constrained to `CallNode`s
73-
// // as `resolvedSummaryBase` is.
74-
// private import semmle.python.frameworks.data.internal.ApiGraphModels as AGM
75-
//
76-
// private class SummarizedCallableFromModel extends SummarizedCallable {
77-
// string package;
78-
// string type;
79-
// string path;
80-
// SummarizedCallableFromModel() {
81-
// ModelOutput::relevantSummaryModel(package, type, path, _, _, _) and
82-
// this = package + ";" + type + ";" + path
83-
// }
84-
// override CallCfgNode getACall() {
85-
// exists(API::CallNode base |
86-
// ModelOutput::resolvedSummaryBase(package, type, path, base) and
87-
// result = base.getACall()
88-
// )
89-
// }
90-
// override ArgumentNode getACallback() {
91-
// exists(API::Node base |
92-
// base = AGM::getNodeFromPath(package, type, path) and
93-
// result = base.getAValueReachableFromSource()
94-
// )
95-
// }
96-
// override predicate propagatesFlowExt(string input, string output, boolean preservesValue) {
97-
// exists(string kind |
98-
// ModelOutput::relevantSummaryModel(package, type, path, input, output, kind)
99-
// |
100-
// kind = "value" and
101-
// preservesValue = true
102-
// or
103-
// kind = "taint" and
104-
// preservesValue = false
105-
// )
106-
// }
107-
// }
72+
73+
private class SummarizedCallableFromModel extends SummarizedCallable {
74+
string type;
75+
string path;
76+
77+
SummarizedCallableFromModel() {
78+
ModelOutput::relevantSummaryModel(type, path, _, _, _) and
79+
this = type + ";" + path
80+
}
81+
82+
override CallCfgNode getACall() {
83+
exists(API::CallNode base |
84+
ModelOutput::resolvedSummaryBase(type, path, base) and
85+
result = base.getACall()
86+
)
87+
}
88+
89+
override ArgumentNode getACallback() {
90+
exists(API::Node base |
91+
ModelOutput::resolvedSummaryRefBase(type, path, base) and
92+
result = base.getAValueReachableFromSource()
93+
)
94+
}
95+
96+
override predicate propagatesFlowExt(string input, string output, boolean preservesValue) {
97+
exists(string kind | ModelOutput::relevantSummaryModel(type, path, input, output, kind) |
98+
kind = "value" and
99+
preservesValue = true
100+
or
101+
kind = "taint" and
102+
preservesValue = false
103+
)
104+
}
105+
}

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

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

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

0 commit comments

Comments
 (0)