@@ -82,9 +82,9 @@ private import codeql.mad.ModelValidation as SharedModelVal
82
82
83
83
/** Holds if `package` have MaD framework coverage. */
84
84
private predicate packageHasMaDCoverage ( string package ) {
85
- sourceModel ( package , _, _, _, _, _, _, _, _) or
86
- sinkModel ( package , _, _, _, _, _, _, _, _) or
87
- summaryModel ( package , _, _, _, _, _, _, _, _, _)
85
+ sourceModel ( package , _, _, _, _, _, _, _, _, _ ) or
86
+ sinkModel ( package , _, _, _, _, _, _, _, _, _ ) or
87
+ summaryModel ( package , _, _, _, _, _, _, _, _, _, _ )
88
88
}
89
89
90
90
/**
@@ -128,23 +128,24 @@ predicate modelCoverage(string package, int pkgs, string kind, string part, int
128
128
strictcount ( string subpkg , string type , boolean subtypes , string name , string signature ,
129
129
string ext , string output , string provenance |
130
130
canonicalPackageHasASubpackage ( package , subpkg ) and
131
- sourceModel ( subpkg , type , subtypes , name , signature , ext , output , kind , provenance )
131
+ sourceModel ( subpkg , type , subtypes , name , signature , ext , output , kind , provenance , _ )
132
132
)
133
133
or
134
134
part = "sink" and
135
135
n =
136
136
strictcount ( string subpkg , string type , boolean subtypes , string name , string signature ,
137
137
string ext , string input , string provenance |
138
138
canonicalPackageHasASubpackage ( package , subpkg ) and
139
- sinkModel ( subpkg , type , subtypes , name , signature , ext , input , kind , provenance )
139
+ sinkModel ( subpkg , type , subtypes , name , signature , ext , input , kind , provenance , _ )
140
140
)
141
141
or
142
142
part = "summary" and
143
143
n =
144
144
strictcount ( string subpkg , string type , boolean subtypes , string name , string signature ,
145
145
string ext , string input , string output , string provenance |
146
146
canonicalPackageHasASubpackage ( package , subpkg ) and
147
- summaryModel ( subpkg , type , subtypes , name , signature , ext , input , output , kind , provenance )
147
+ summaryModel ( subpkg , type , subtypes , name , signature , ext , input , output , kind , provenance ,
148
+ _)
148
149
)
149
150
)
150
151
}
@@ -153,9 +154,9 @@ predicate modelCoverage(string package, int pkgs, string kind, string part, int
153
154
module ModelValidation {
154
155
private string getInvalidModelInput ( ) {
155
156
exists ( string pred , AccessPath input , string part |
156
- sinkModel ( _, _, _, _, _, _, input , _, _) and pred = "sink"
157
+ sinkModel ( _, _, _, _, _, _, input , _, _, _ ) and pred = "sink"
157
158
or
158
- summaryModel ( _, _, _, _, _, _, input , _, _, _) and pred = "summary"
159
+ summaryModel ( _, _, _, _, _, _, input , _, _, _, _ ) and pred = "summary"
159
160
|
160
161
(
161
162
invalidSpecComponent ( input , part ) and
@@ -171,9 +172,9 @@ module ModelValidation {
171
172
172
173
private string getInvalidModelOutput ( ) {
173
174
exists ( string pred , string output , string part |
174
- sourceModel ( _, _, _, _, _, _, output , _, _) and pred = "source"
175
+ sourceModel ( _, _, _, _, _, _, output , _, _, _ ) and pred = "source"
175
176
or
176
- summaryModel ( _, _, _, _, _, _, _, output , _, _) and pred = "summary"
177
+ summaryModel ( _, _, _, _, _, _, _, output , _, _, _ ) and pred = "summary"
177
178
|
178
179
invalidSpecComponent ( output , part ) and
179
180
not part = "" and
@@ -183,11 +184,11 @@ module ModelValidation {
183
184
}
184
185
185
186
private module KindValConfig implements SharedModelVal:: KindValidationConfigSig {
186
- predicate summaryKind ( string kind ) { summaryModel ( _, _, _, _, _, _, _, _, kind , _) }
187
+ predicate summaryKind ( string kind ) { summaryModel ( _, _, _, _, _, _, _, _, kind , _, _ ) }
187
188
188
- predicate sinkKind ( string kind ) { sinkModel ( _, _, _, _, _, _, _, kind , _) }
189
+ predicate sinkKind ( string kind ) { sinkModel ( _, _, _, _, _, _, _, kind , _, _ ) }
189
190
190
- predicate sourceKind ( string kind ) { sourceModel ( _, _, _, _, _, _, _, kind , _) }
191
+ predicate sourceKind ( string kind ) { sourceModel ( _, _, _, _, _, _, _, kind , _, _ ) }
191
192
}
192
193
193
194
private module KindVal = SharedModelVal:: KindValidation< KindValConfig > ;
@@ -197,11 +198,12 @@ module ModelValidation {
197
198
string pred , string package , string type , string name , string signature , string ext ,
198
199
string provenance
199
200
|
200
- sourceModel ( package , type , _, name , signature , ext , _, _, provenance ) and pred = "source"
201
+ sourceModel ( package , type , _, name , signature , ext , _, _, provenance , _ ) and pred = "source"
201
202
or
202
- sinkModel ( package , type , _, name , signature , ext , _, _, provenance ) and pred = "sink"
203
+ sinkModel ( package , type , _, name , signature , ext , _, _, provenance , _ ) and pred = "sink"
203
204
or
204
- summaryModel ( package , type , _, name , signature , ext , _, _, _, provenance ) and pred = "summary"
205
+ summaryModel ( package , type , _, name , signature , ext , _, _, _, provenance , _) and
206
+ pred = "summary"
205
207
|
206
208
not package .replaceAll ( "$ANYVERSION" , "" ) .regexpMatch ( "[a-zA-Z0-9_\\./-]*" ) and
207
209
result = "Dubious package \"" + package + "\" in " + pred + " model."
@@ -237,9 +239,9 @@ pragma[nomagic]
237
239
private predicate elementSpec (
238
240
string package , string type , boolean subtypes , string name , string signature , string ext
239
241
) {
240
- sourceModel ( package , type , subtypes , name , signature , ext , _, _, _) or
241
- sinkModel ( package , type , subtypes , name , signature , ext , _, _, _) or
242
- summaryModel ( package , type , subtypes , name , signature , ext , _, _, _, _)
242
+ sourceModel ( package , type , subtypes , name , signature , ext , _, _, _, _ ) or
243
+ sinkModel ( package , type , subtypes , name , signature , ext , _, _, _, _ ) or
244
+ summaryModel ( package , type , subtypes , name , signature , ext , _, _, _, _, _ )
243
245
}
244
246
245
247
private string paramsStringPart ( Function f , int i ) {
@@ -297,8 +299,8 @@ predicate hasExternalSpecification(Function f) {
297
299
f = any ( SummarizedCallable sc ) .asFunction ( )
298
300
or
299
301
exists ( SourceSinkInterpretationInput:: SourceOrSinkElement e | f = e .asEntity ( ) |
300
- SourceSinkInterpretationInput:: sourceElement ( e , _, _, _) or
301
- SourceSinkInterpretationInput:: sinkElement ( e , _, _, _)
302
+ SourceSinkInterpretationInput:: sourceElement ( e , _, _, _, _ ) or
303
+ SourceSinkInterpretationInput:: sinkElement ( e , _, _, _, _ )
302
304
)
303
305
}
304
306
@@ -351,9 +353,9 @@ private module Cached {
351
353
* model.
352
354
*/
353
355
cached
354
- predicate sourceNode ( DataFlow:: Node node , string kind ) {
356
+ predicate sourceNode ( DataFlow:: Node node , string kind , string model ) {
355
357
exists ( SourceSinkInterpretationInput:: InterpretNode n |
356
- isSourceNode ( n , kind ) and n .asNode ( ) = node
358
+ isSourceNode ( n , kind , model ) and n .asNode ( ) = node
357
359
)
358
360
}
359
361
@@ -362,57 +364,78 @@ private module Cached {
362
364
* model.
363
365
*/
364
366
cached
365
- predicate sinkNode ( DataFlow:: Node node , string kind ) {
367
+ predicate sinkNode ( DataFlow:: Node node , string kind , string model ) {
366
368
exists ( SourceSinkInterpretationInput:: InterpretNode n |
367
- isSinkNode ( n , kind ) and n .asNode ( ) = node
369
+ isSinkNode ( n , kind , model ) and n .asNode ( ) = node
368
370
)
369
371
}
370
372
}
371
373
372
374
import Cached
373
375
376
+ /**
377
+ * Holds if `node` is specified as a source with the given kind in a MaD flow
378
+ * model.
379
+ */
380
+ predicate sourceNode ( DataFlow:: Node node , string kind ) { sourceNode ( node , kind , _) }
381
+
382
+ /**
383
+ * Holds if `node` is specified as a sink with the given kind in a MaD flow
384
+ * model.
385
+ */
386
+ predicate sinkNode ( DataFlow:: Node node , string kind ) { sinkNode ( node , kind , _) }
387
+
374
388
private predicate interpretSummary (
375
- Callable c , string input , string output , string kind , string provenance
389
+ Callable c , string input , string output , string kind , string provenance , string model
376
390
) {
377
391
exists (
378
- string namespace , string type , boolean subtypes , string name , string signature , string ext
392
+ string namespace , string type , boolean subtypes , string name , string signature , string ext ,
393
+ QlBuiltins:: ExtensionId madId
379
394
|
380
- summaryModel ( namespace , type , subtypes , name , signature , ext , input , output , kind , provenance ) and
395
+ summaryModel ( namespace , type , subtypes , name , signature , ext , input , output , kind , provenance ,
396
+ madId ) and
397
+ model = "MaD:" + madId .toString ( ) and
381
398
c .asFunction ( ) = interpretElement ( namespace , type , subtypes , name , signature , ext ) .asEntity ( )
382
399
)
383
400
}
384
401
385
402
// adapter class for converting Mad summaries to `SummarizedCallable`s
386
403
private class SummarizedCallableAdapter extends SummarizedCallable {
387
- SummarizedCallableAdapter ( ) { interpretSummary ( this , _, _, _, _) }
404
+ SummarizedCallableAdapter ( ) { interpretSummary ( this , _, _, _, _, _ ) }
388
405
389
- private predicate relevantSummaryElementManual ( string input , string output , string kind ) {
406
+ private predicate relevantSummaryElementManual (
407
+ string input , string output , string kind , string model
408
+ ) {
390
409
exists ( Provenance provenance |
391
- interpretSummary ( this , input , output , kind , provenance ) and
410
+ interpretSummary ( this , input , output , kind , provenance , model ) and
392
411
provenance .isManual ( )
393
412
)
394
413
}
395
414
396
- private predicate relevantSummaryElementGenerated ( string input , string output , string kind ) {
415
+ private predicate relevantSummaryElementGenerated (
416
+ string input , string output , string kind , string model
417
+ ) {
397
418
exists ( Provenance provenance |
398
- interpretSummary ( this , input , output , kind , provenance ) and
419
+ interpretSummary ( this , input , output , kind , provenance , model ) and
399
420
provenance .isGenerated ( )
400
421
)
401
422
}
402
423
403
- override predicate propagatesFlow ( string input , string output , boolean preservesValue ) {
424
+ override predicate propagatesFlow (
425
+ string input , string output , boolean preservesValue , string model
426
+ ) {
404
427
exists ( string kind |
405
- this .relevantSummaryElementManual ( input , output , kind )
428
+ this .relevantSummaryElementManual ( input , output , kind , model )
406
429
or
407
- not this .relevantSummaryElementManual ( _, _, _) and
408
- this .relevantSummaryElementGenerated ( input , output , kind )
430
+ not this .relevantSummaryElementManual ( _, _, _, _ ) and
431
+ this .relevantSummaryElementGenerated ( input , output , kind , model )
409
432
|
410
433
if kind = "value" then preservesValue = true else preservesValue = false
411
434
)
412
435
}
413
436
414
437
override predicate hasProvenance ( Provenance provenance ) {
415
- interpretSummary ( this , _, _, _, provenance )
438
+ interpretSummary ( this , _, _, _, provenance , _ )
416
439
}
417
440
}
418
441
0 commit comments