@@ -33,6 +33,11 @@ module MakeImpl<DataFlowParameter Lang> {
3333 */
3434 predicate isSink ( Node sink , FlowState state ) ;
3535
36+ /**
37+ * Holds if `sink` is a relevant data flow sink for any state.
38+ */
39+ predicate isSink ( Node sink ) ;
40+
3641 /**
3742 * Holds if data flow through `node` is prohibited. This completely removes
3843 * `node` from the data flow graph.
@@ -216,8 +221,11 @@ module MakeImpl<DataFlowParameter Lang> {
216221 private predicate outBarrier ( NodeEx node ) {
217222 exists ( Node n |
218223 node .asNode ( ) = n and
219- Config:: isBarrierOut ( n ) and
224+ Config:: isBarrierOut ( n )
225+ |
220226 Config:: isSink ( n , _)
227+ or
228+ Config:: isSink ( n )
221229 )
222230 }
223231
@@ -230,7 +238,8 @@ module MakeImpl<DataFlowParameter Lang> {
230238 not Config:: isSource ( n , _)
231239 or
232240 Config:: isBarrierOut ( n ) and
233- not Config:: isSink ( n , _)
241+ not Config:: isSink ( n , _) and
242+ not Config:: isSink ( n )
234243 )
235244 }
236245
@@ -247,7 +256,7 @@ module MakeImpl<DataFlowParameter Lang> {
247256 }
248257
249258 pragma [ nomagic]
250- private predicate sinkNode ( NodeEx node , FlowState state ) {
259+ private predicate sinkNodeWithState ( NodeEx node , FlowState state ) {
251260 Config:: isSink ( node .asNode ( ) , state ) and
252261 not fullBarrier ( node ) and
253262 not stateBarrier ( node , state )
@@ -645,6 +654,16 @@ module MakeImpl<DataFlowParameter Lang> {
645654 )
646655 }
647656
657+ additional predicate sinkNode ( NodeEx node , FlowState state ) {
658+ fwdFlow ( node ) and
659+ fwdFlowState ( state ) and
660+ Config:: isSink ( node .asNode ( ) )
661+ or
662+ fwdFlow ( node ) and
663+ fwdFlowState ( state ) and
664+ sinkNodeWithState ( node , state )
665+ }
666+
648667 /**
649668 * Holds if `node` is part of a path from a source to a sink.
650669 *
@@ -659,12 +678,8 @@ module MakeImpl<DataFlowParameter Lang> {
659678
660679 pragma [ nomagic]
661680 private predicate revFlow0 ( NodeEx node , boolean toReturn ) {
662- exists ( FlowState state |
663- fwdFlow ( node ) and
664- sinkNode ( node , state ) and
665- fwdFlowState ( state ) and
666- if hasSinkCallCtx ( ) then toReturn = true else toReturn = false
667- )
681+ sinkNode ( node , _) and
682+ if hasSinkCallCtx ( ) then toReturn = true else toReturn = false
668683 or
669684 exists ( NodeEx mid | revFlow ( mid , toReturn ) |
670685 localFlowStepEx ( node , mid ) or
@@ -920,6 +935,8 @@ module MakeImpl<DataFlowParameter Lang> {
920935 /* End: Stage 1 logic. */
921936 }
922937
938+ private predicate sinkNode = Stage1:: sinkNode / 2 ;
939+
923940 pragma [ noinline]
924941 private predicate localFlowStepNodeCand1 ( NodeEx node1 , NodeEx node2 ) {
925942 Stage1:: revFlow ( node2 ) and
@@ -3894,7 +3911,10 @@ module MakeImpl<DataFlowParameter Lang> {
38943911 }
38953912
38963913 private predicate interestingCallableSink ( DataFlowCallable c ) {
3897- exists ( Node n | Config:: isSink ( n , _) and c = getNodeEnclosingCallable ( n ) )
3914+ exists ( Node n | c = getNodeEnclosingCallable ( n ) |
3915+ Config:: isSink ( n , _) or
3916+ Config:: isSink ( n )
3917+ )
38983918 or
38993919 exists ( DataFlowCallable mid | interestingCallableSink ( mid ) and callableStep ( c , mid ) )
39003920 }
@@ -3926,8 +3946,10 @@ module MakeImpl<DataFlowParameter Lang> {
39263946 or
39273947 exists ( Node n |
39283948 ce2 = TCallableSink ( ) and
3929- Config:: isSink ( n , _) and
39303949 ce1 = TCallable ( getNodeEnclosingCallable ( n ) )
3950+ |
3951+ Config:: isSink ( n , _) or
3952+ Config:: isSink ( n )
39313953 )
39323954 }
39333955
0 commit comments