7676private import go
7777import internal.ExternalFlowExtensions
7878private import internal.DataFlowPrivate
79+ private import internal.FlowSummaryImpl
80+ private import internal.FlowSummaryImpl:: Private
7981private import internal.FlowSummaryImpl:: Private:: External
80- private import internal.FlowSummaryImplSpecific
81- private import internal.AccessPathSyntax
82- private import FlowSummary
82+ private import internal.FlowSummaryImpl:: Public
8383private import codeql.mad.ModelValidation as SharedModelVal
8484
8585/** Holds if `package` have MaD framework coverage. */
@@ -274,7 +274,7 @@ private string interpretPackage(string p) {
274274}
275275
276276/** Gets the source/sink/summary element corresponding to the supplied parameters. */
277- SourceOrSinkElement interpretElement (
277+ SourceSinkInterpretationInput :: SourceOrSinkElement interpretElement (
278278 string pkg , string type , boolean subtypes , string name , string signature , string ext
279279) {
280280 elementSpec ( pkg , type , subtypes , name , signature , ext ) and
@@ -298,8 +298,9 @@ SourceOrSinkElement interpretElement(
298298predicate hasExternalSpecification ( Function f ) {
299299 f = any ( SummarizedCallable sc ) .asFunction ( )
300300 or
301- exists ( SourceOrSinkElement e | f = e .asEntity ( ) |
302- sourceElement ( e , _, _, _) or sinkElement ( e , _, _, _)
301+ exists ( SourceSinkInterpretationInput:: SourceOrSinkElement e | f = e .asEntity ( ) |
302+ SourceSinkInterpretationInput:: sourceElement ( e , _, _) or
303+ SourceSinkInterpretationInput:: sinkElement ( e , _, _)
303304 )
304305}
305306
@@ -353,7 +354,9 @@ private module Cached {
353354 */
354355 cached
355356 predicate sourceNode ( DataFlow:: Node node , string kind ) {
356- exists ( InterpretNode n | isSourceNode ( n , kind ) and n .asNode ( ) = node )
357+ exists ( SourceSinkInterpretationInput:: InterpretNode n |
358+ isSourceNode ( n , kind ) and n .asNode ( ) = node
359+ )
357360 }
358361
359362 /**
@@ -362,8 +365,71 @@ private module Cached {
362365 */
363366 cached
364367 predicate sinkNode ( DataFlow:: Node node , string kind ) {
365- exists ( InterpretNode n | isSinkNode ( n , kind ) and n .asNode ( ) = node )
368+ exists ( SourceSinkInterpretationInput:: InterpretNode n |
369+ isSinkNode ( n , kind ) and n .asNode ( ) = node
370+ )
366371 }
367372}
368373
369374import Cached
375+
376+ private predicate interpretSummary (
377+ Callable c , string input , string output , string kind , string provenance
378+ ) {
379+ exists (
380+ string namespace , string type , boolean subtypes , string name , string signature , string ext
381+ |
382+ summaryModel ( namespace , type , subtypes , name , signature , ext , input , output , kind , provenance ) and
383+ c .asFunction ( ) = interpretElement ( namespace , type , subtypes , name , signature , ext ) .asEntity ( )
384+ )
385+ }
386+
387+ private class SummarizedCallableAdapter extends SummarizedCallable {
388+ SummarizedCallableAdapter ( ) { interpretSummary ( this , _, _, _, _) }
389+
390+ private predicate relevantSummaryElementManual ( string input , string output , string kind ) {
391+ exists ( Provenance provenance |
392+ interpretSummary ( this , input , output , kind , provenance ) and
393+ provenance .isManual ( )
394+ )
395+ }
396+
397+ private predicate relevantSummaryElementGenerated ( string input , string output , string kind ) {
398+ exists ( Provenance provenance |
399+ interpretSummary ( this , input , output , kind , provenance ) and
400+ provenance .isGenerated ( )
401+ )
402+ }
403+
404+ override predicate propagatesFlow ( string input , string output , boolean preservesValue ) {
405+ exists ( string kind |
406+ this .relevantSummaryElementManual ( input , output , kind )
407+ or
408+ not this .relevantSummaryElementManual ( _, _, _) and
409+ this .relevantSummaryElementGenerated ( input , output , kind )
410+ |
411+ if kind = "value" then preservesValue = true else preservesValue = false
412+ )
413+ }
414+
415+ override predicate hasProvenance ( Provenance provenance ) {
416+ interpretSummary ( this , _, _, _, provenance )
417+ }
418+ }
419+
420+ private class NeutralCallableAdapter extends NeutralCallable {
421+ string kind ;
422+ string provenance_ ;
423+
424+ NeutralCallableAdapter ( ) {
425+ // Neutral models have not been implemented for Go.
426+ none ( ) and
427+ exists ( this ) and
428+ exists ( kind ) and
429+ exists ( provenance_ )
430+ }
431+
432+ override string getKind ( ) { result = kind }
433+
434+ override predicate hasProvenance ( Provenance provenance ) { provenance = provenance_ }
435+ }
0 commit comments