Skip to content

Commit 36ba3ba

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 fe65fb8 commit 36ba3ba

File tree

2 files changed

+37
-35
lines changed

2 files changed

+37
-35
lines changed

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

Lines changed: 36 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -69,39 +69,41 @@ abstract class SummarizedCallable extends LibraryCallable, Impl::Public::Summari
6969
}
7070

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

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -522,7 +522,7 @@ private API::Node getNodeFromSubPath(API::Node base, AccessPath subPath) {
522522
}
523523

524524
/** Gets the node identified by the given `(type, path)` tuple. */
525-
private API::Node getNodeFromPath(string type, AccessPath path) {
525+
API::Node getNodeFromPath(string type, AccessPath path) {
526526
result = getNodeFromPath(type, path, path.getNumToken())
527527
}
528528

0 commit comments

Comments
 (0)