Skip to content

Commit ebb3485

Browse files
committed
Go: Use the extensible predicates for model definitions.
1 parent 5fd687d commit ebb3485

File tree

3 files changed

+24
-65
lines changed

3 files changed

+24
-65
lines changed

go/ql/lib/ext/builtin.model.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
extensions:
2+
- addsTo:
3+
pack: codeql/go-all
4+
extensible: summaryModel
5+
data:
6+
- ["", "", False, "append", "", "", "Argument[0].ArrayElement", "ReturnValue.ArrayElement", "value", "manual"]
7+
- ["", "", False, "append", "", "", "Argument[1]", "ReturnValue.ArrayElement", "value", "manual"]

go/ql/lib/ext/dummy.model.yml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
extensions:
2+
# Make sure that the extensible model predicates are at least defined as empty.
3+
- addsTo:
4+
pack: codeql/go-all
5+
extensible: sourceModel
6+
data: []
7+
- addsTo:
8+
pack: codeql/go-all
9+
extensible: sinkModel
10+
data: []
11+
- addsTo:
12+
pack: codeql/go-all
13+
extensible: summaryModel
14+
data: []

go/ql/lib/semmle/go/dataflow/ExternalFlow.qll

Lines changed: 3 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -76,16 +76,6 @@ private module Frameworks {
7676
private import semmle.go.frameworks.Stdlib
7777
}
7878

79-
private class BuiltinModel extends SummaryModelCsv {
80-
override predicate row(string row) {
81-
row =
82-
[
83-
";;false;append;;;Argument[0].ArrayElement;ReturnValue.ArrayElement;value",
84-
";;false;append;;;Argument[1];ReturnValue.ArrayElement;value"
85-
]
86-
}
87-
}
88-
8979
/**
9080
* A unit class for adding additional source model rows.
9181
*
@@ -126,65 +116,13 @@ predicate sinkModel(string row) { any(SinkModelCsv s).row(row) }
126116
predicate summaryModel(string row) { any(SummaryModelCsv s).row(row) }
127117

128118
/** Holds if a source model exists for the given parameters. */
129-
predicate sourceModel(
130-
string namespace, string type, boolean subtypes, string name, string signature, string ext,
131-
string output, string kind, string provenance
132-
) {
133-
exists(string row |
134-
sourceModel(row) and
135-
row.splitAt(";", 0) = namespace and
136-
row.splitAt(";", 1) = type and
137-
row.splitAt(";", 2) = subtypes.toString() and
138-
subtypes = [true, false] and
139-
row.splitAt(";", 3) = name and
140-
row.splitAt(";", 4) = signature and
141-
row.splitAt(";", 5) = ext and
142-
row.splitAt(";", 6) = output and
143-
row.splitAt(";", 7) = kind and
144-
provenance = "manual"
145-
)
146-
}
119+
predicate sourceModel = Extensions::sourceModel/9;
147120

148121
/** Holds if a sink model exists for the given parameters. */
149-
predicate sinkModel(
150-
string namespace, string type, boolean subtypes, string name, string signature, string ext,
151-
string input, string kind, string provenance
152-
) {
153-
exists(string row |
154-
sinkModel(row) and
155-
row.splitAt(";", 0) = namespace and
156-
row.splitAt(";", 1) = type and
157-
row.splitAt(";", 2) = subtypes.toString() and
158-
subtypes = [true, false] and
159-
row.splitAt(";", 3) = name and
160-
row.splitAt(";", 4) = signature and
161-
row.splitAt(";", 5) = ext and
162-
row.splitAt(";", 6) = input and
163-
row.splitAt(";", 7) = kind and
164-
provenance = "manual"
165-
)
166-
}
122+
predicate sinkModel = Extensions::sinkModel/9;
167123

168124
/** Holds if a summary model exists for the given parameters. */
169-
predicate summaryModel(
170-
string namespace, string type, boolean subtypes, string name, string signature, string ext,
171-
string input, string output, string kind, string provenance
172-
) {
173-
exists(string row |
174-
summaryModel(row) and
175-
row.splitAt(";", 0) = namespace and
176-
row.splitAt(";", 1) = type and
177-
row.splitAt(";", 2) = subtypes.toString() and
178-
subtypes = [true, false] and
179-
row.splitAt(";", 3) = name and
180-
row.splitAt(";", 4) = signature and
181-
row.splitAt(";", 5) = ext and
182-
row.splitAt(";", 6) = input and
183-
row.splitAt(";", 7) = output and
184-
row.splitAt(";", 8) = kind
185-
) and
186-
provenance = "manual"
187-
}
125+
predicate summaryModel = Extensions::summaryModel/10;
188126

189127
/** Holds if `package` have CSV framework coverage. */
190128
private predicate packageHasCsvCoverage(string package) {

0 commit comments

Comments
 (0)