@@ -97,9 +97,9 @@ private import semmle.code.csharp.commons.QualifiedName
9797private import codeql.mad.ModelValidation as SharedModelVal
9898
9999private predicate relevantNamespace ( string namespace ) {
100- sourceModel ( namespace , _, _, _, _, _, _, _, _) or
101- sinkModel ( namespace , _, _, _, _, _, _, _, _) or
102- summaryModel ( namespace , _, _, _, _, _, _, _, _, _)
100+ sourceModel ( namespace , _, _, _, _, _, _, _, _, _ ) or
101+ sinkModel ( namespace , _, _, _, _, _, _, _, _, _ ) or
102+ summaryModel ( namespace , _, _, _, _, _, _, _, _, _, _ )
103103}
104104
105105private predicate namespaceLink ( string shortns , string longns ) {
@@ -129,23 +129,23 @@ predicate modelCoverage(string namespace, int namespaces, string kind, string pa
129129 strictcount ( string subns , string type , boolean subtypes , string name , string signature ,
130130 string ext , string output , string provenance |
131131 canonicalNamespaceLink ( namespace , subns ) and
132- sourceModel ( subns , type , subtypes , name , signature , ext , output , kind , provenance )
132+ sourceModel ( subns , type , subtypes , name , signature , ext , output , kind , provenance , _ )
133133 )
134134 or
135135 part = "sink" and
136136 n =
137137 strictcount ( string subns , string type , boolean subtypes , string name , string signature ,
138138 string ext , string input , string provenance |
139139 canonicalNamespaceLink ( namespace , subns ) and
140- sinkModel ( subns , type , subtypes , name , signature , ext , input , kind , provenance )
140+ sinkModel ( subns , type , subtypes , name , signature , ext , input , kind , provenance , _ )
141141 )
142142 or
143143 part = "summary" and
144144 n =
145145 strictcount ( string subns , string type , boolean subtypes , string name , string signature ,
146146 string ext , string input , string output , string provenance |
147147 canonicalNamespaceLink ( namespace , subns ) and
148- summaryModel ( subns , type , subtypes , name , signature , ext , input , output , kind , provenance )
148+ summaryModel ( subns , type , subtypes , name , signature , ext , input , output , kind , provenance , _ )
149149 )
150150 )
151151}
@@ -155,10 +155,10 @@ module ModelValidation {
155155 private import codeql.dataflow.internal.AccessPathSyntax as AccessPathSyntax
156156
157157 private predicate getRelevantAccessPath ( string path ) {
158- summaryModel ( _, _, _, _, _, _, path , _, _, _) or
159- summaryModel ( _, _, _, _, _, _, _, path , _, _) or
160- sinkModel ( _, _, _, _, _, _, path , _, _) or
161- sourceModel ( _, _, _, _, _, _, path , _, _)
158+ summaryModel ( _, _, _, _, _, _, path , _, _, _, _ ) or
159+ summaryModel ( _, _, _, _, _, _, _, path , _, _, _ ) or
160+ sinkModel ( _, _, _, _, _, _, path , _, _, _ ) or
161+ sourceModel ( _, _, _, _, _, _, path , _, _, _ )
162162 }
163163
164164 private module MkAccessPath = AccessPathSyntax:: AccessPath< getRelevantAccessPath / 1 > ;
@@ -169,9 +169,9 @@ module ModelValidation {
169169
170170 private string getInvalidModelInput ( ) {
171171 exists ( string pred , AccessPath input , AccessPathToken part |
172- sinkModel ( _, _, _, _, _, _, input , _, _) and pred = "sink"
172+ sinkModel ( _, _, _, _, _, _, input , _, _, _ ) and pred = "sink"
173173 or
174- summaryModel ( _, _, _, _, _, _, input , _, _, _) and pred = "summary"
174+ summaryModel ( _, _, _, _, _, _, input , _, _, _, _ ) and pred = "summary"
175175 |
176176 (
177177 invalidSpecComponent ( input , part ) and
@@ -191,9 +191,9 @@ module ModelValidation {
191191
192192 private string getInvalidModelOutput ( ) {
193193 exists ( string pred , AccessPath output , AccessPathToken part |
194- sourceModel ( _, _, _, _, _, _, output , _, _) and pred = "source"
194+ sourceModel ( _, _, _, _, _, _, output , _, _, _ ) and pred = "source"
195195 or
196- summaryModel ( _, _, _, _, _, _, _, output , _, _) and pred = "summary"
196+ summaryModel ( _, _, _, _, _, _, _, output , _, _, _ ) and pred = "summary"
197197 |
198198 (
199199 invalidSpecComponent ( output , part ) and
@@ -208,11 +208,11 @@ module ModelValidation {
208208 }
209209
210210 private module KindValConfig implements SharedModelVal:: KindValidationConfigSig {
211- predicate summaryKind ( string kind ) { summaryModel ( _, _, _, _, _, _, _, _, kind , _) }
211+ predicate summaryKind ( string kind ) { summaryModel ( _, _, _, _, _, _, _, _, kind , _, _ ) }
212212
213- predicate sinkKind ( string kind ) { sinkModel ( _, _, _, _, _, _, _, kind , _) }
213+ predicate sinkKind ( string kind ) { sinkModel ( _, _, _, _, _, _, _, kind , _, _ ) }
214214
215- predicate sourceKind ( string kind ) { sourceModel ( _, _, _, _, _, _, _, kind , _) }
215+ predicate sourceKind ( string kind ) { sourceModel ( _, _, _, _, _, _, _, kind , _, _ ) }
216216
217217 predicate neutralKind ( string kind ) { neutralModel ( _, _, _, _, kind , _) }
218218 }
@@ -224,11 +224,11 @@ module ModelValidation {
224224 string pred , string namespace , string type , string name , string signature , string ext ,
225225 string provenance
226226 |
227- sourceModel ( namespace , type , _, name , signature , ext , _, _, provenance ) and pred = "source"
227+ sourceModel ( namespace , type , _, name , signature , ext , _, _, provenance , _ ) and pred = "source"
228228 or
229- sinkModel ( namespace , type , _, name , signature , ext , _, _, provenance ) and pred = "sink"
229+ sinkModel ( namespace , type , _, name , signature , ext , _, _, provenance , _ ) and pred = "sink"
230230 or
231- summaryModel ( namespace , type , _, name , signature , ext , _, _, _, provenance ) and
231+ summaryModel ( namespace , type , _, name , signature , ext , _, _, _, provenance , _ ) and
232232 pred = "summary"
233233 or
234234 neutralModel ( namespace , type , name , signature , _, provenance ) and
@@ -268,11 +268,11 @@ module ModelValidation {
268268private predicate elementSpec (
269269 string namespace , string type , boolean subtypes , string name , string signature , string ext
270270) {
271- sourceModel ( namespace , type , subtypes , name , signature , ext , _, _, _)
271+ sourceModel ( namespace , type , subtypes , name , signature , ext , _, _, _, _ )
272272 or
273- sinkModel ( namespace , type , subtypes , name , signature , ext , _, _, _)
273+ sinkModel ( namespace , type , subtypes , name , signature , ext , _, _, _, _ )
274274 or
275- summaryModel ( namespace , type , subtypes , name , signature , ext , _, _, _, _)
275+ summaryModel ( namespace , type , subtypes , name , signature , ext , _, _, _, _, _ )
276276 or
277277 neutralModel ( namespace , type , name , signature , _, _) and ext = "" and subtypes = false
278278}
@@ -393,14 +393,14 @@ Declaration interpretElement(
393393 * A callable where there exists a MaD sink model that applies to it.
394394 */
395395class SinkCallable extends Callable {
396- SinkCallable ( ) { SourceSinkInterpretationInput:: sinkElement ( this , _, _, _) }
396+ SinkCallable ( ) { SourceSinkInterpretationInput:: sinkElement ( this , _, _, _, _ ) }
397397}
398398
399399/**
400400 * A callable where there exists a MaD source model that applies to it.
401401 */
402402class SourceCallable extends Callable {
403- SourceCallable ( ) { SourceSinkInterpretationInput:: sourceElement ( this , _, _, _) }
403+ SourceCallable ( ) { SourceSinkInterpretationInput:: sourceElement ( this , _, _, _, _ ) }
404404}
405405
406406cached
@@ -410,9 +410,9 @@ private module Cached {
410410 * model.
411411 */
412412 cached
413- predicate sourceNode ( Node node , string kind ) {
413+ predicate sourceNode ( Node node , string kind , string model ) {
414414 exists ( SourceSinkInterpretationInput:: InterpretNode n |
415- isSourceNode ( n , kind ) and n .asNode ( ) = node
415+ isSourceNode ( n , kind , model ) and n .asNode ( ) = node
416416 )
417417 }
418418
@@ -421,15 +421,27 @@ private module Cached {
421421 * model.
422422 */
423423 cached
424- predicate sinkNode ( Node node , string kind ) {
424+ predicate sinkNode ( Node node , string kind , string model ) {
425425 exists ( SourceSinkInterpretationInput:: InterpretNode n |
426- isSinkNode ( n , kind ) and n .asNode ( ) = node
426+ isSinkNode ( n , kind , model ) and n .asNode ( ) = node
427427 )
428428 }
429429}
430430
431431import Cached
432432
433+ /**
434+ * Holds if `node` is specified as a source with the given kind in a MaD flow
435+ * model.
436+ */
437+ predicate sourceNode ( Node node , string kind ) { sourceNode ( node , kind , _) }
438+
439+ /**
440+ * Holds if `node` is specified as a sink with the given kind in a MaD flow
441+ * model.
442+ */
443+ predicate sinkNode ( Node node , string kind ) { sinkNode ( node , kind , _) }
444+
433445/** Holds if the summary should apply for all overrides of `c`. */
434446predicate isBaseCallableOrPrototype ( UnboundCallable c ) {
435447 c .getDeclaringType ( ) instanceof Interface
@@ -517,12 +529,15 @@ string asPartialNeutralModel(UnboundCallable c) {
517529}
518530
519531private predicate interpretSummary (
520- UnboundCallable c , string input , string output , string kind , string provenance
532+ UnboundCallable c , string input , string output , string kind , string provenance , string model
521533) {
522534 exists (
523- string namespace , string type , boolean subtypes , string name , string signature , string ext
535+ string namespace , string type , boolean subtypes , string name , string signature , string ext ,
536+ QlBuiltins:: ExtensionId madId
524537 |
525- summaryModel ( namespace , type , subtypes , name , signature , ext , input , output , kind , provenance ) and
538+ summaryModel ( namespace , type , subtypes , name , signature , ext , input , output , kind , provenance ,
539+ madId ) and
540+ model = "MaD:" + madId .toString ( ) and
526541 c = interpretElement ( namespace , type , subtypes , name , signature , ext )
527542 )
528543}
@@ -536,18 +551,22 @@ private predicate interpretNeutral(UnboundCallable c, string kind, string proven
536551
537552// adapter class for converting Mad summaries to `SummarizedCallable`s
538553private class SummarizedCallableAdapter extends SummarizedCallable {
539- SummarizedCallableAdapter ( ) { interpretSummary ( this , _, _, _, _) }
554+ SummarizedCallableAdapter ( ) { interpretSummary ( this , _, _, _, _, _ ) }
540555
541- private predicate relevantSummaryElementManual ( string input , string output , string kind ) {
556+ private predicate relevantSummaryElementManual (
557+ string input , string output , string kind , string model
558+ ) {
542559 exists ( Provenance provenance |
543- interpretSummary ( this , input , output , kind , provenance ) and
560+ interpretSummary ( this , input , output , kind , provenance , model ) and
544561 provenance .isManual ( )
545562 )
546563 }
547564
548- private predicate relevantSummaryElementGenerated ( string input , string output , string kind ) {
565+ private predicate relevantSummaryElementGenerated (
566+ string input , string output , string kind , string model
567+ ) {
549568 exists ( Provenance provenance |
550- interpretSummary ( this , input , output , kind , provenance ) and
569+ interpretSummary ( this , input , output , kind , provenance , model ) and
551570 provenance .isGenerated ( )
552571 ) and
553572 not exists ( Provenance provenance |
@@ -556,19 +575,21 @@ private class SummarizedCallableAdapter extends SummarizedCallable {
556575 )
557576 }
558577
559- override predicate propagatesFlow ( string input , string output , boolean preservesValue ) {
578+ override predicate propagatesFlow (
579+ string input , string output , boolean preservesValue , string model
580+ ) {
560581 exists ( string kind |
561- this .relevantSummaryElementManual ( input , output , kind )
582+ this .relevantSummaryElementManual ( input , output , kind , model )
562583 or
563- not this .relevantSummaryElementManual ( _, _, _) and
564- this .relevantSummaryElementGenerated ( input , output , kind )
584+ not this .relevantSummaryElementManual ( _, _, _, _ ) and
585+ this .relevantSummaryElementGenerated ( input , output , kind , model )
565586 |
566587 if kind = "value" then preservesValue = true else preservesValue = false
567588 )
568589 }
569590
570591 override predicate hasProvenance ( Provenance provenance ) {
571- interpretSummary ( this , _, _, _, provenance )
592+ interpretSummary ( this , _, _, _, provenance , _ )
572593 }
573594}
574595
0 commit comments