Skip to content

Commit 0725251

Browse files
committed
Java/C++: Thread additional models through the shared lib.
1 parent 47dcf05 commit 0725251

File tree

7 files changed

+226
-170
lines changed

7 files changed

+226
-170
lines changed

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

Lines changed: 71 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -106,10 +106,6 @@ private import codeql.mad.ModelValidation as SharedModelVal
106106
private import codeql.util.Unit
107107
private import codeql.mad.static.MaD as SharedMaD
108108

109-
private module MaD = SharedMaD::ModelsAsData<Extensions>;
110-
111-
import MaD
112-
113109
/**
114110
* A unit class for adding additional source model rows.
115111
*
@@ -149,92 +145,80 @@ predicate sinkModel(string row) { any(SinkModelCsv s).row(row) }
149145
/** Holds if `row` is a summary model. */
150146
predicate summaryModel(string row) { any(SummaryModelCsv s).row(row) }
151147

152-
/** Holds if a source model exists for the given parameters. */
153-
predicate sourceModel(
154-
string namespace, string type, boolean subtypes, string name, string signature, string ext,
155-
string output, string kind, string provenance, string model
156-
) {
157-
exists(string row |
158-
sourceModel(row) and
159-
row.splitAt(";", 0) = namespace and
160-
row.splitAt(";", 1) = type and
161-
row.splitAt(";", 2) = subtypes.toString() and
162-
subtypes = [true, false] and
163-
row.splitAt(";", 3) = name and
164-
row.splitAt(";", 4) = signature and
165-
row.splitAt(";", 5) = ext and
166-
row.splitAt(";", 6) = output and
167-
row.splitAt(";", 7) = kind
168-
) and
169-
provenance = "manual" and
170-
model = ""
171-
or
172-
exists(QlBuiltins::ExtensionId madId |
173-
Extensions::sourceModel(namespace, type, subtypes, name, signature, ext, output, kind,
174-
provenance, madId) and
175-
model = "MaD:" + madId.toString()
176-
)
177-
}
148+
private module MadInput implements SharedMaD::InputSig {
149+
/** Holds if a source model exists for the given parameters. */
150+
predicate additionalSourceModel(
151+
string namespace, string type, boolean subtypes, string name, string signature, string ext,
152+
string output, string kind, string provenance, string model
153+
) {
154+
exists(string row |
155+
sourceModel(row) and
156+
row.splitAt(";", 0) = namespace and
157+
row.splitAt(";", 1) = type and
158+
row.splitAt(";", 2) = subtypes.toString() and
159+
subtypes = [true, false] and
160+
row.splitAt(";", 3) = name and
161+
row.splitAt(";", 4) = signature and
162+
row.splitAt(";", 5) = ext and
163+
row.splitAt(";", 6) = output and
164+
row.splitAt(";", 7) = kind
165+
) and
166+
provenance = "manual" and
167+
model = ""
168+
}
178169

179-
/** Holds if a sink model exists for the given parameters. */
180-
predicate sinkModel(
181-
string namespace, string type, boolean subtypes, string name, string signature, string ext,
182-
string input, string kind, string provenance, string model
183-
) {
184-
exists(string row |
185-
sinkModel(row) and
186-
row.splitAt(";", 0) = namespace and
187-
row.splitAt(";", 1) = type and
188-
row.splitAt(";", 2) = subtypes.toString() and
189-
subtypes = [true, false] and
190-
row.splitAt(";", 3) = name and
191-
row.splitAt(";", 4) = signature and
192-
row.splitAt(";", 5) = ext and
193-
row.splitAt(";", 6) = input and
194-
row.splitAt(";", 7) = kind
195-
) and
196-
provenance = "manual" and
197-
model = ""
198-
or
199-
exists(QlBuiltins::ExtensionId madId |
200-
Extensions::sinkModel(namespace, type, subtypes, name, signature, ext, input, kind, provenance,
201-
madId) and
202-
model = "MaD:" + madId.toString()
203-
)
204-
}
170+
/** Holds if a sink model exists for the given parameters. */
171+
predicate additionalSinkModel(
172+
string namespace, string type, boolean subtypes, string name, string signature, string ext,
173+
string input, string kind, string provenance, string model
174+
) {
175+
exists(string row |
176+
sinkModel(row) and
177+
row.splitAt(";", 0) = namespace and
178+
row.splitAt(";", 1) = type and
179+
row.splitAt(";", 2) = subtypes.toString() and
180+
subtypes = [true, false] and
181+
row.splitAt(";", 3) = name and
182+
row.splitAt(";", 4) = signature and
183+
row.splitAt(";", 5) = ext and
184+
row.splitAt(";", 6) = input and
185+
row.splitAt(";", 7) = kind
186+
) and
187+
provenance = "manual" and
188+
model = ""
189+
}
205190

206-
/**
207-
* Holds if a summary model exists for the given parameters.
208-
*
209-
* This predicate does not expand `@` to `*`s.
210-
*/
211-
private predicate summaryModel0(
212-
string namespace, string type, boolean subtypes, string name, string signature, string ext,
213-
string input, string output, string kind, string provenance, string model
214-
) {
215-
exists(string row |
216-
summaryModel(row) and
217-
row.splitAt(";", 0) = namespace and
218-
row.splitAt(";", 1) = type and
219-
row.splitAt(";", 2) = subtypes.toString() and
220-
subtypes = [true, false] and
221-
row.splitAt(";", 3) = name and
222-
row.splitAt(";", 4) = signature and
223-
row.splitAt(";", 5) = ext and
224-
row.splitAt(";", 6) = input and
225-
row.splitAt(";", 7) = output and
226-
row.splitAt(";", 8) = kind
227-
) and
228-
provenance = "manual" and
229-
model = ""
230-
or
231-
exists(QlBuiltins::ExtensionId madId |
232-
Extensions::summaryModel(namespace, type, subtypes, name, signature, ext, input, output, kind,
233-
provenance, madId) and
234-
model = "MaD:" + madId.toString()
235-
)
191+
/**
192+
* Holds if a summary model exists for the given parameters.
193+
*
194+
* This predicate does not expand `@` to `*`s.
195+
*/
196+
predicate additionalSummaryModel(
197+
string namespace, string type, boolean subtypes, string name, string signature, string ext,
198+
string input, string output, string kind, string provenance, string model
199+
) {
200+
exists(string row |
201+
summaryModel(row) and
202+
row.splitAt(";", 0) = namespace and
203+
row.splitAt(";", 1) = type and
204+
row.splitAt(";", 2) = subtypes.toString() and
205+
subtypes = [true, false] and
206+
row.splitAt(";", 3) = name and
207+
row.splitAt(";", 4) = signature and
208+
row.splitAt(";", 5) = ext and
209+
row.splitAt(";", 6) = input and
210+
row.splitAt(";", 7) = output and
211+
row.splitAt(";", 8) = kind
212+
) and
213+
provenance = "manual" and
214+
model = ""
215+
}
236216
}
237217

218+
private module MaD = SharedMaD::ModelsAsData<Extensions, MadInput>;
219+
220+
import MaD
221+
238222
/**
239223
* Holds if `input` is `input0`, but with all occurrences of `@` replaced
240224
* by `n` repetitions of `*` (and similarly for `output` and `output0`).
@@ -256,7 +240,7 @@ predicate summaryModel(
256240
string input, string output, string kind, string provenance, string model
257241
) {
258242
exists(string input0, string output0 |
259-
summaryModel0(namespace, type, subtypes, name, signature, ext, input0, output0, kind,
243+
MaD::summaryModel(namespace, type, subtypes, name, signature, ext, input0, output0, kind,
260244
provenance, model) and
261245
expandInputAndOutput(input0, input, output0, output,
262246
[0 .. Private::getMaxElementContentIndirectionIndex() - 1])

csharp/ql/lib/semmle/code/csharp/dataflow/internal/ExternalFlow.qll

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@
8888
*/
8989

9090
import csharp
91-
import ExternalFlowExtensions
91+
private import ExternalFlowExtensions::Extensions as Extensions
9292
private import DataFlowDispatch
9393
private import DataFlowPrivate
9494
private import DataFlowPublic
@@ -103,7 +103,9 @@ private import codeql.dataflow.internal.AccessPathSyntax as AccessPathSyntax
103103
private import codeql.mad.ModelValidation as SharedModelVal
104104
private import codeql.mad.static.MaD as SharedMaD
105105

106-
private module MaD = SharedMaD::ModelsAsData<Extensions>;
106+
private module MadInput implements SharedMaD::InputSig { }
107+
108+
private module MaD = SharedMaD::ModelsAsData<Extensions, MadInput>;
107109

108110
import MaD
109111

@@ -169,7 +171,7 @@ module ModelValidation {
169171

170172
predicate sourceKind(string kind) { sourceModel(_, _, _, _, _, _, _, kind, _, _) }
171173

172-
predicate neutralKind(string kind) { neutralModel(_, _, _, _, kind, _) }
174+
predicate neutralKind(string kind) { Extensions::neutralModel(_, _, _, _, kind, _) }
173175
}
174176

175177
private module KindVal = SharedModelVal::KindValidation<KindValConfig>;
@@ -186,7 +188,7 @@ module ModelValidation {
186188
summaryModel(namespace, type, _, name, signature, ext, _, _, _, provenance, _) and
187189
pred = "summary"
188190
or
189-
neutralModel(namespace, type, name, signature, _, provenance) and
191+
Extensions::neutralModel(namespace, type, name, signature, _, provenance) and
190192
ext = "" and
191193
pred = "neutral"
192194
|
@@ -229,7 +231,7 @@ private predicate elementSpec(
229231
or
230232
summaryModel(namespace, type, subtypes, name, signature, ext, _, _, _, _, _)
231233
or
232-
neutralModel(namespace, type, name, signature, _, _) and ext = "" and subtypes = true
234+
Extensions::neutralModel(namespace, type, name, signature, _, _) and ext = "" and subtypes = true
233235
}
234236

235237
private predicate elementSpec(
@@ -501,19 +503,17 @@ private predicate interpretSummary(
501503
UnboundCallable c, string input, string output, string kind, string provenance, string model
502504
) {
503505
exists(
504-
string namespace, string type, boolean subtypes, string name, string signature, string ext,
505-
QlBuiltins::ExtensionId madId
506+
string namespace, string type, boolean subtypes, string name, string signature, string ext
506507
|
507508
summaryModel(namespace, type, subtypes, name, signature, ext, input, output, kind, provenance,
508-
madId) and
509-
model = "MaD:" + madId.toString() and
509+
model) and
510510
c = interpretElement(namespace, type, subtypes, name, signature, ext)
511511
)
512512
}
513513

514514
predicate interpretNeutral(UnboundCallable c, string kind, string provenance) {
515515
exists(string namespace, string type, string name, string signature |
516-
neutralModel(namespace, type, name, signature, kind, provenance) and
516+
Extensions::neutralModel(namespace, type, name, signature, kind, provenance) and
517517
c = interpretElement(namespace, type, true, name, signature, "")
518518
)
519519
}

csharp/ql/lib/semmle/code/csharp/dataflow/internal/FlowSummaryImpl.qll

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -213,11 +213,9 @@ module SourceSinkInterpretationInput implements
213213
Element e, string output, string kind, Public::Provenance provenance, string model
214214
) {
215215
exists(
216-
string namespace, string type, boolean subtypes, string name, string signature, string ext,
217-
QlBuiltins::ExtensionId madId
216+
string namespace, string type, boolean subtypes, string name, string signature, string ext
218217
|
219-
sourceModel(namespace, type, subtypes, name, signature, ext, output, kind, provenance, madId) and
220-
model = "MaD:" + madId.toString() and
218+
sourceModel(namespace, type, subtypes, name, signature, ext, output, kind, provenance, model) and
221219
e = interpretElement(namespace, type, subtypes, name, signature, ext)
222220
)
223221
}
@@ -226,11 +224,9 @@ module SourceSinkInterpretationInput implements
226224
Element e, string input, string kind, Public::Provenance provenance, string model
227225
) {
228226
exists(
229-
string namespace, string type, boolean subtypes, string name, string signature, string ext,
230-
QlBuiltins::ExtensionId madId
227+
string namespace, string type, boolean subtypes, string name, string signature, string ext
231228
|
232-
sinkModel(namespace, type, subtypes, name, signature, ext, input, kind, provenance, madId) and
233-
model = "MaD:" + madId.toString() and
229+
sinkModel(namespace, type, subtypes, name, signature, ext, input, kind, provenance, model) and
234230
e = interpretElement(namespace, type, subtypes, name, signature, ext)
235231
)
236232
}

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,9 @@ private import internal.FlowSummaryImpl::Private::External
9696
private import codeql.mad.ModelValidation as SharedModelVal
9797
private import codeql.mad.static.MaD as SharedMaD
9898

99-
private module MaD = SharedMaD::ModelsAsData<Extensions>;
99+
private module MadInput implements SharedMaD::InputSig { }
100+
101+
private module MaD = SharedMaD::ModelsAsData<Extensions, MadInput>;
100102

101103
import MaD
102104

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

Lines changed: 41 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,47 @@ private import internal.ExternalFlowExtensions::Extensions as Extensions
102102
private import codeql.mad.ModelValidation as SharedModelVal
103103
private import codeql.mad.static.MaD as SharedMaD
104104

105-
private module MaD = SharedMaD::ModelsAsData<Extensions>;
105+
private module MadInput implements SharedMaD::InputSig {
106+
/** Holds if a source model exists for the given parameters. */
107+
predicate additionalSourceModel(
108+
string package, string type, boolean subtypes, string name, string signature, string ext,
109+
string output, string kind, string provenance, string model
110+
) {
111+
exists(QlBuiltins::ExtensionId madId |
112+
any(ActiveExperimentalModelsInternal q)
113+
.sourceModel(package, type, subtypes, name, signature, ext, output, kind, provenance,
114+
madId) and
115+
model = "MaD:" + madId.toString()
116+
)
117+
}
118+
119+
/** Holds if a sink model exists for the given parameters. */
120+
predicate additionalSinkModel(
121+
string package, string type, boolean subtypes, string name, string signature, string ext,
122+
string input, string kind, string provenance, string model
123+
) {
124+
exists(QlBuiltins::ExtensionId madId |
125+
any(ActiveExperimentalModelsInternal q)
126+
.sinkModel(package, type, subtypes, name, signature, ext, input, kind, provenance, madId) and
127+
model = "MaD:" + madId.toString()
128+
)
129+
}
130+
131+
/** Holds if a summary model exists for the given parameters. */
132+
predicate additionalSummaryModel(
133+
string package, string type, boolean subtypes, string name, string signature, string ext,
134+
string input, string output, string kind, string provenance, string model
135+
) {
136+
exists(QlBuiltins::ExtensionId madId |
137+
any(ActiveExperimentalModelsInternal q)
138+
.summaryModel(package, type, subtypes, name, signature, ext, input, output, kind,
139+
provenance, madId) and
140+
model = "MaD:" + madId.toString()
141+
)
142+
}
143+
}
144+
145+
private module MaD = SharedMaD::ModelsAsData<Extensions, MadInput>;
106146

107147
import MaD
108148

@@ -152,34 +192,6 @@ abstract private class ActiveExperimentalModelsInternal extends string {
152192

153193
deprecated class ActiveExperimentalModels = ActiveExperimentalModelsInternal;
154194

155-
/** Holds if a source model exists for the given parameters. */
156-
predicate sourceModel(
157-
string package, string type, boolean subtypes, string name, string signature, string ext,
158-
string output, string kind, string provenance, QlBuiltins::ExtensionId madId
159-
) {
160-
(
161-
Extensions::sourceModel(package, type, subtypes, name, signature, ext, output, kind, provenance,
162-
madId)
163-
or
164-
any(ActiveExperimentalModelsInternal q)
165-
.sourceModel(package, type, subtypes, name, signature, ext, output, kind, provenance, madId)
166-
)
167-
}
168-
169-
/** Holds if a sink model exists for the given parameters. */
170-
predicate sinkModel(
171-
string package, string type, boolean subtypes, string name, string signature, string ext,
172-
string input, string kind, string provenance, QlBuiltins::ExtensionId madId
173-
) {
174-
(
175-
Extensions::sinkModel(package, type, subtypes, name, signature, ext, input, kind, provenance,
176-
madId)
177-
or
178-
any(ActiveExperimentalModelsInternal q)
179-
.sinkModel(package, type, subtypes, name, signature, ext, input, kind, provenance, madId)
180-
)
181-
}
182-
183195
/** Holds if a barrier model exists for the given parameters. */
184196
predicate barrierModel(
185197
string package, string type, boolean subtypes, string name, string signature, string ext,
@@ -198,21 +210,6 @@ predicate barrierGuardModel(
198210
acceptingvalue, kind, provenance, madId)
199211
}
200212

201-
/** Holds if a summary model exists for the given parameters. */
202-
predicate summaryModel(
203-
string package, string type, boolean subtypes, string name, string signature, string ext,
204-
string input, string output, string kind, string provenance, QlBuiltins::ExtensionId madId
205-
) {
206-
(
207-
Extensions::summaryModel(package, type, subtypes, name, signature, ext, input, output, kind,
208-
provenance, madId)
209-
or
210-
any(ActiveExperimentalModelsInternal q)
211-
.summaryModel(package, type, subtypes, name, signature, ext, input, output, kind,
212-
provenance, madId)
213-
)
214-
}
215-
216213
/**
217214
* Holds if the given extension tuple `madId` should pretty-print as `model`.
218215
*

0 commit comments

Comments
 (0)