Skip to content

Commit 94413c8

Browse files
committed
C++: Implement YML extension models.
1 parent 34130d5 commit 94413c8

File tree

12 files changed

+94
-2
lines changed

12 files changed

+94
-2
lines changed

cpp/ql/lib/ext/empty.model.yml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
extensions:
2+
# Make sure that the extensible model predicates have at least one definition
3+
# to avoid errors about undefined extensionals.
4+
- addsTo:
5+
pack: codeql/cpp-all
6+
extensible: sourceModel
7+
data: []
8+
- addsTo:
9+
pack: codeql/cpp-all
10+
extensible: sinkModel
11+
data: []
12+
- addsTo:
13+
pack: codeql/cpp-all
14+
extensible: summaryModel
15+
data: []

cpp/ql/lib/qlpack.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,6 @@ dependencies:
1414
codeql/tutorial: ${workspace}
1515
codeql/util: ${workspace}
1616
codeql/xml: ${workspace}
17+
dataExtensions:
18+
- ext/*.model.yml
1719
warnOnImplicitThis: true

cpp/ql/lib/semmle/code/cpp/dataflow/ExternalFlow.qll

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ private import internal.FlowSummaryImpl
7878
private import internal.FlowSummaryImpl::Public
7979
private import internal.FlowSummaryImpl::Private
8080
private import internal.FlowSummaryImpl::Private::External
81+
private import internal.ExternalFlowExtensions as Extensions
8182
private import codeql.mad.ModelValidation as SharedModelVal
8283
private import codeql.util.Unit
8384

@@ -138,6 +139,9 @@ predicate sourceModel(
138139
row.splitAt(";", 7) = kind
139140
) and
140141
provenance = "manual"
142+
or
143+
Extensions::sourceModel(namespace, type, subtypes, name, signature, ext, output, kind, provenance,
144+
_)
141145
}
142146

143147
/** Holds if a sink model exists for the given parameters. */
@@ -158,6 +162,8 @@ predicate sinkModel(
158162
row.splitAt(";", 7) = kind
159163
) and
160164
provenance = "manual"
165+
or
166+
Extensions::sinkModel(namespace, type, subtypes, name, signature, ext, input, kind, provenance, _)
161167
}
162168

163169
/** Holds if a summary model exists for the given parameters. */
@@ -179,6 +185,9 @@ predicate summaryModel(
179185
row.splitAt(";", 8) = kind
180186
) and
181187
provenance = "manual"
188+
or
189+
Extensions::summaryModel(namespace, type, subtypes, name, signature, ext, input, output, kind,
190+
provenance, _)
182191
}
183192

184193
private predicate relevantNamespace(string namespace) {
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/**
2+
* This module provides extensible predicates for defining MaD models.
3+
*/
4+
5+
/**
6+
* Holds if an external source model exists for the given parameters.
7+
*/
8+
extensible predicate sourceModel(
9+
string namespace, string type, boolean subtypes, string name, string signature, string ext,
10+
string output, string kind, string provenance, QlBuiltins::ExtensionId madId
11+
);
12+
13+
/**
14+
* Holds if an external sink model exists for the given parameters.
15+
*/
16+
extensible predicate sinkModel(
17+
string namespace, string type, boolean subtypes, string name, string signature, string ext,
18+
string input, string kind, string provenance, QlBuiltins::ExtensionId madId
19+
);
20+
21+
/**
22+
* Holds if an external summary model exists for the given parameters.
23+
*/
24+
extensible predicate summaryModel(
25+
string namespace, string type, boolean subtypes, string name, string signature, string ext,
26+
string input, string output, string kind, string provenance, QlBuiltins::ExtensionId madId
27+
);
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
extensions:
2+
- addsTo:
3+
pack: codeql/cpp-all
4+
extensible: sourceModel
5+
data: # namespace, type, subtypes, name, signature, ext, output, kind, provenance
6+
- ["", "", False, "ymlSource", "", "", "ReturnValue", "local", "manual"]
7+
- addsTo:
8+
pack: codeql/cpp-all
9+
extensible: sinkModel
10+
data: # namespace, type, subtypes, name, signature, ext, input, kind, provenance
11+
- ["", "", False, "ymlSink", "", "", "Argument[0]", "test-sink", "manual"]
12+
- addsTo:
13+
pack: codeql/cpp-all
14+
extensible: summaryModel
15+
data: # namespace, type, subtypes, name, signature, ext, input, output, kind, provenance
16+
- ["", "", False, "ymlStep", "", "", "Argument[0]", "ReturnValue", "taint", "manual"]
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
| test.cpp:9:10:9:10 | 0 | test-sink |
2+
| test.cpp:11:10:11:10 | x | test-sink |
3+
| test.cpp:15:10:15:10 | y | test-sink |
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
extensions:
2+
- addsTo:
3+
pack: codeql/cpp-all
4+
extensible: sinkModel
5+
data: # namespace, type, subtypes, name, signature, ext, input, kind, provenance
6+
- ["", "", False, "ymlSink", "", "", "Argument[0]", "test-sink", "manual"]
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
| test.cpp:7:10:7:18 | call to ymlSource | local |
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
extensions:
2+
- addsTo:
3+
pack: codeql/cpp-all
4+
extensible: sourceModel
5+
data: # namespace, type, subtypes, name, signature, ext, output, kind, provenance
6+
- ["", "", False, "ymlSource", "", "", "ReturnValue", "local", "manual"]
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
| test.cpp:13:18:13:18 | x | test.cpp:13:10:13:16 | call to ymlStep |

0 commit comments

Comments
 (0)