8989
9090import java
9191private import semmle.code.java.dataflow.DataFlow:: DataFlow
92+ private import FlowSummary as FlowSummary
9293private import internal.DataFlowPrivate
94+ private import internal.FlowSummaryImpl
95+ private import internal.FlowSummaryImpl:: Public
96+ private import internal.FlowSummaryImpl:: Private
9397private import internal.FlowSummaryImpl:: Private:: External
94- private import internal.FlowSummaryImplSpecific as FlowSummaryImplSpecific
95- private import internal.AccessPathSyntax
9698private import internal.ExternalFlowExtensions as Extensions
97- private import FlowSummary
9899private import codeql.mad.ModelValidation as SharedModelVal
99100
100101/**
@@ -234,6 +235,21 @@ predicate modelCoverage(string package, int pkgs, string kind, string part, int
234235
235236/** Provides a query predicate to check the MaD models for validation errors. */
236237module 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+
237253 private string getInvalidModelInput ( ) {
238254 exists ( string pred , AccessPath input , AccessPathToken part |
239255 sinkModel ( _, _, _, _, _, _, input , _, _) and pred = "sink"
@@ -478,7 +494,9 @@ private module Cached {
478494 */
479495 cached
480496 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+ )
482500 }
483501
484502 /**
@@ -487,8 +505,54 @@ private module Cached {
487505 */
488506 cached
489507 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+ )
491511 }
492512}
493513
494514import 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