89
89
90
90
import java
91
91
private import semmle.code.java.dataflow.DataFlow:: DataFlow
92
+ private import FlowSummary as FlowSummary
92
93
private import internal.DataFlowPrivate
94
+ private import internal.FlowSummaryImpl
95
+ private import internal.FlowSummaryImpl:: Public
96
+ private import internal.FlowSummaryImpl:: Private
93
97
private import internal.FlowSummaryImpl:: Private:: External
94
- private import internal.FlowSummaryImplSpecific as FlowSummaryImplSpecific
95
- private import internal.AccessPathSyntax
96
98
private import internal.ExternalFlowExtensions as Extensions
97
- private import FlowSummary
98
99
private import codeql.mad.ModelValidation as SharedModelVal
99
100
100
101
/**
@@ -234,6 +235,21 @@ predicate modelCoverage(string package, int pkgs, string kind, string part, int
234
235
235
236
/** Provides a query predicate to check the MaD models for validation errors. */
236
237
module ModelValidation {
238
+ private import codeql.dataflow.internal.AccessPathSyntax as AccessPathSyntax
239
+
240
+ private predicate getRelevantAccessPath ( string path ) {
241
+ summaryModel ( _, _, _, _, _, _, path , _, _, _) or
242
+ summaryModel ( _, _, _, _, _, _, _, path , _, _) or
243
+ sinkModel ( _, _, _, _, _, _, path , _, _) or
244
+ sourceModel ( _, _, _, _, _, _, path , _, _)
245
+ }
246
+
247
+ private module MkAccessPath = AccessPathSyntax:: AccessPath< getRelevantAccessPath / 1 > ;
248
+
249
+ class AccessPath = MkAccessPath:: AccessPath ;
250
+
251
+ class AccessPathToken = MkAccessPath:: AccessPathToken ;
252
+
237
253
private string getInvalidModelInput ( ) {
238
254
exists ( string pred , AccessPath input , AccessPathToken part |
239
255
sinkModel ( _, _, _, _, _, _, input , _, _) and pred = "sink"
@@ -478,7 +494,9 @@ private module Cached {
478
494
*/
479
495
cached
480
496
predicate sourceNode ( Node node , string kind ) {
481
- exists ( FlowSummaryImplSpecific:: InterpretNode n | isSourceNode ( n , kind ) and n .asNode ( ) = node )
497
+ exists ( SourceSinkInterpretationInput:: InterpretNode n |
498
+ isSourceNode ( n , kind ) and n .asNode ( ) = node
499
+ )
482
500
}
483
501
484
502
/**
@@ -487,8 +505,54 @@ private module Cached {
487
505
*/
488
506
cached
489
507
predicate sinkNode ( Node node , string kind ) {
490
- exists ( FlowSummaryImplSpecific:: InterpretNode n | isSinkNode ( n , kind ) and n .asNode ( ) = node )
508
+ exists ( SourceSinkInterpretationInput:: InterpretNode n |
509
+ isSinkNode ( n , kind ) and n .asNode ( ) = node
510
+ )
491
511
}
492
512
}
493
513
494
514
import Cached
515
+
516
+ private class SummarizedCallableAdapter extends SummarizedCallable {
517
+ SummarizedCallableAdapter ( ) { summaryElement ( this , _, _, _, _) }
518
+
519
+ private predicate relevantSummaryElementManual ( string input , string output , string kind ) {
520
+ exists ( Provenance provenance |
521
+ summaryElement ( this , input , output , kind , provenance ) and
522
+ provenance .isManual ( )
523
+ )
524
+ }
525
+
526
+ private predicate relevantSummaryElementGenerated ( string input , string output , string kind ) {
527
+ exists ( Provenance provenance |
528
+ summaryElement ( this , input , output , kind , provenance ) and
529
+ provenance .isGenerated ( )
530
+ )
531
+ }
532
+
533
+ override predicate propagatesFlow ( string input , string output , boolean preservesValue ) {
534
+ exists ( string kind |
535
+ this .relevantSummaryElementManual ( input , output , kind )
536
+ or
537
+ not this .relevantSummaryElementManual ( _, _, _) and
538
+ this .relevantSummaryElementGenerated ( input , output , kind )
539
+ |
540
+ if kind = "value" then preservesValue = true else preservesValue = false
541
+ )
542
+ }
543
+
544
+ override predicate hasProvenance ( Provenance provenance ) {
545
+ summaryElement ( this , _, _, _, provenance )
546
+ }
547
+ }
548
+
549
+ private class NeutralCallableAdapter extends NeutralCallable {
550
+ string kind ;
551
+ string provenance_ ;
552
+
553
+ NeutralCallableAdapter ( ) { neutralElement ( this , kind , provenance_ ) }
554
+
555
+ override string getKind ( ) { result = kind }
556
+
557
+ override predicate hasProvenance ( Provenance provenance ) { provenance = provenance_ }
558
+ }
0 commit comments