@@ -600,15 +600,52 @@ signature predicate guardChecksSig(GuardNode g, ControlFlowNode node, boolean br
600600module BarrierGuard< guardChecksSig / 3 guardChecks> {
601601 /** Gets a node that is safely guarded by the given guard check. */
602602 ExprNode getABarrierNode ( ) {
603+ result = ParameterizedBarrierGuard< Unit , extendedGuardChecks / 4 > :: getABarrierNode ( _)
604+ }
605+
606+ private predicate extendedGuardChecks ( GuardNode g , ControlFlowNode node , boolean branch , Unit u ) {
607+ guardChecks ( g , node , branch )
608+ }
609+ }
610+
611+ bindingset [ this ]
612+ private signature class ParamSig ;
613+
614+ private module WithParam< ParamSig P> {
615+ signature predicate guardChecksSig ( GuardNode g , ControlFlowNode node , boolean branch , P param ) ;
616+ }
617+
618+ module ParameterizedBarrierGuard< ParamSig P, WithParam< P > :: guardChecksSig / 4 guardChecks> {
619+ /** Gets a node that is safely guarded by the given guard check with parameter `param`. */
620+ ExprNode getABarrierNode ( P param ) {
603621 exists ( GuardNode g , EssaDefinition def , ControlFlowNode node , boolean branch |
604622 AdjacentUses:: useOfDef ( def , node ) and
605- guardChecks ( g , node , branch ) and
623+ guardChecks ( g , node , branch , param ) and
606624 AdjacentUses:: useOfDef ( def , result .asCfgNode ( ) ) and
607625 g .controlsBlock ( result .asCfgNode ( ) .getBasicBlock ( ) , branch )
608626 )
609627 }
610628}
611629
630+ module ExternalBarrierGuard {
631+ private import semmle.python.ApiGraphs
632+
633+ predicate guardCheck ( GuardNode g , ControlFlowNode node , boolean branch , string kind ) {
634+ exists ( API:: CallNode call , API:: Node parameter |
635+ parameter = call .getAParameter ( ) and
636+ parameter = ModelOutput:: getABarrierGuardNode ( kind , branch )
637+ |
638+ g = call .asCfgNode ( ) and
639+ node = parameter .asSink ( ) .asCfgNode ( )
640+ )
641+ }
642+
643+ /** Gets a node that is an external barrier of the given kind. */
644+ ExprNode getAnExternalBarrierNode ( string kind ) {
645+ result = ParameterizedBarrierGuard< string , guardCheck / 4 > :: getABarrierNode ( kind )
646+ }
647+ }
648+
612649/**
613650 * Algebraic datatype for tracking data content associated with values.
614651 * Content can be collection elements or object attributes.
0 commit comments