@@ -82,9 +82,9 @@ private import codeql.mad.ModelValidation as SharedModelVal
8282
8383/** Holds if `package` have MaD framework coverage. */
8484private 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 , _, _, _, _, _, _, _, _, _, _ )
8888}
8989
9090/**
@@ -128,23 +128,24 @@ predicate modelCoverage(string package, int pkgs, string kind, string part, int
128128 strictcount ( string subpkg , string type , boolean subtypes , string name , string signature ,
129129 string ext , string output , string provenance |
130130 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 , _ )
132132 )
133133 or
134134 part = "sink" and
135135 n =
136136 strictcount ( string subpkg , string type , boolean subtypes , string name , string signature ,
137137 string ext , string input , string provenance |
138138 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 , _ )
140140 )
141141 or
142142 part = "summary" and
143143 n =
144144 strictcount ( string subpkg , string type , boolean subtypes , string name , string signature ,
145145 string ext , string input , string output , string provenance |
146146 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+ _)
148149 )
149150 )
150151}
@@ -153,9 +154,9 @@ predicate modelCoverage(string package, int pkgs, string kind, string part, int
153154module ModelValidation {
154155 private string getInvalidModelInput ( ) {
155156 exists ( string pred , AccessPath input , string part |
156- sinkModel ( _, _, _, _, _, _, input , _, _) and pred = "sink"
157+ sinkModel ( _, _, _, _, _, _, input , _, _, _ ) and pred = "sink"
157158 or
158- summaryModel ( _, _, _, _, _, _, input , _, _, _) and pred = "summary"
159+ summaryModel ( _, _, _, _, _, _, input , _, _, _, _ ) and pred = "summary"
159160 |
160161 (
161162 invalidSpecComponent ( input , part ) and
@@ -171,9 +172,9 @@ module ModelValidation {
171172
172173 private string getInvalidModelOutput ( ) {
173174 exists ( string pred , string output , string part |
174- sourceModel ( _, _, _, _, _, _, output , _, _) and pred = "source"
175+ sourceModel ( _, _, _, _, _, _, output , _, _, _ ) and pred = "source"
175176 or
176- summaryModel ( _, _, _, _, _, _, _, output , _, _) and pred = "summary"
177+ summaryModel ( _, _, _, _, _, _, _, output , _, _, _ ) and pred = "summary"
177178 |
178179 invalidSpecComponent ( output , part ) and
179180 not part = "" and
@@ -183,11 +184,11 @@ module ModelValidation {
183184 }
184185
185186 private module KindValConfig implements SharedModelVal:: KindValidationConfigSig {
186- predicate summaryKind ( string kind ) { summaryModel ( _, _, _, _, _, _, _, _, kind , _) }
187+ predicate summaryKind ( string kind ) { summaryModel ( _, _, _, _, _, _, _, _, kind , _, _ ) }
187188
188- predicate sinkKind ( string kind ) { sinkModel ( _, _, _, _, _, _, _, kind , _) }
189+ predicate sinkKind ( string kind ) { sinkModel ( _, _, _, _, _, _, _, kind , _, _ ) }
189190
190- predicate sourceKind ( string kind ) { sourceModel ( _, _, _, _, _, _, _, kind , _) }
191+ predicate sourceKind ( string kind ) { sourceModel ( _, _, _, _, _, _, _, kind , _, _ ) }
191192 }
192193
193194 private module KindVal = SharedModelVal:: KindValidation< KindValConfig > ;
@@ -197,11 +198,12 @@ module ModelValidation {
197198 string pred , string package , string type , string name , string signature , string ext ,
198199 string provenance
199200 |
200- sourceModel ( package , type , _, name , signature , ext , _, _, provenance ) and pred = "source"
201+ sourceModel ( package , type , _, name , signature , ext , _, _, provenance , _ ) and pred = "source"
201202 or
202- sinkModel ( package , type , _, name , signature , ext , _, _, provenance ) and pred = "sink"
203+ sinkModel ( package , type , _, name , signature , ext , _, _, provenance , _ ) and pred = "sink"
203204 or
204- summaryModel ( package , type , _, name , signature , ext , _, _, _, provenance ) and pred = "summary"
205+ summaryModel ( package , type , _, name , signature , ext , _, _, _, provenance , _) and
206+ pred = "summary"
205207 |
206208 not package .replaceAll ( "$ANYVERSION" , "" ) .regexpMatch ( "[a-zA-Z0-9_\\./-]*" ) and
207209 result = "Dubious package \"" + package + "\" in " + pred + " model."
@@ -237,9 +239,9 @@ pragma[nomagic]
237239private predicate elementSpec (
238240 string package , string type , boolean subtypes , string name , string signature , string ext
239241) {
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 , _, _, _, _, _ )
243245}
244246
245247private string paramsStringPart ( Function f , int i ) {
@@ -297,8 +299,8 @@ predicate hasExternalSpecification(Function f) {
297299 f = any ( SummarizedCallable sc ) .asFunction ( )
298300 or
299301 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 , _, _, _, _ )
302304 )
303305}
304306
@@ -351,9 +353,9 @@ private module Cached {
351353 * model.
352354 */
353355 cached
354- predicate sourceNode ( DataFlow:: Node node , string kind ) {
356+ predicate sourceNode ( DataFlow:: Node node , string kind , string model ) {
355357 exists ( SourceSinkInterpretationInput:: InterpretNode n |
356- isSourceNode ( n , kind ) and n .asNode ( ) = node
358+ isSourceNode ( n , kind , model ) and n .asNode ( ) = node
357359 )
358360 }
359361
@@ -362,57 +364,78 @@ private module Cached {
362364 * model.
363365 */
364366 cached
365- predicate sinkNode ( DataFlow:: Node node , string kind ) {
367+ predicate sinkNode ( DataFlow:: Node node , string kind , string model ) {
366368 exists ( SourceSinkInterpretationInput:: InterpretNode n |
367- isSinkNode ( n , kind ) and n .asNode ( ) = node
369+ isSinkNode ( n , kind , model ) and n .asNode ( ) = node
368370 )
369371 }
370372}
371373
372374import Cached
373375
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+
374388private 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
376390) {
377391 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
379394 |
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
381398 c .asFunction ( ) = interpretElement ( namespace , type , subtypes , name , signature , ext ) .asEntity ( )
382399 )
383400}
384401
385402// adapter class for converting Mad summaries to `SummarizedCallable`s
386403private class SummarizedCallableAdapter extends SummarizedCallable {
387- SummarizedCallableAdapter ( ) { interpretSummary ( this , _, _, _, _) }
404+ SummarizedCallableAdapter ( ) { interpretSummary ( this , _, _, _, _, _ ) }
388405
389- private predicate relevantSummaryElementManual ( string input , string output , string kind ) {
406+ private predicate relevantSummaryElementManual (
407+ string input , string output , string kind , string model
408+ ) {
390409 exists ( Provenance provenance |
391- interpretSummary ( this , input , output , kind , provenance ) and
410+ interpretSummary ( this , input , output , kind , provenance , model ) and
392411 provenance .isManual ( )
393412 )
394413 }
395414
396- private predicate relevantSummaryElementGenerated ( string input , string output , string kind ) {
415+ private predicate relevantSummaryElementGenerated (
416+ string input , string output , string kind , string model
417+ ) {
397418 exists ( Provenance provenance |
398- interpretSummary ( this , input , output , kind , provenance ) and
419+ interpretSummary ( this , input , output , kind , provenance , model ) and
399420 provenance .isGenerated ( )
400421 )
401422 }
402423
403- override predicate propagatesFlow ( string input , string output , boolean preservesValue ) {
424+ override predicate propagatesFlow (
425+ string input , string output , boolean preservesValue , string model
426+ ) {
404427 exists ( string kind |
405- this .relevantSummaryElementManual ( input , output , kind )
428+ this .relevantSummaryElementManual ( input , output , kind , model )
406429 or
407- not this .relevantSummaryElementManual ( _, _, _) and
408- this .relevantSummaryElementGenerated ( input , output , kind )
430+ not this .relevantSummaryElementManual ( _, _, _, _ ) and
431+ this .relevantSummaryElementGenerated ( input , output , kind , model )
409432 |
410433 if kind = "value" then preservesValue = true else preservesValue = false
411434 )
412435 }
413436
414437 override predicate hasProvenance ( Provenance provenance ) {
415- interpretSummary ( this , _, _, _, provenance )
438+ interpretSummary ( this , _, _, _, provenance , _ )
416439 }
417440}
418441
0 commit comments