@@ -561,13 +561,14 @@ module MakeImpl<LocationSig Location, InputSig<Location> Lang> {
561
561
cc = true
562
562
or
563
563
// flow out of a callable
564
- fwdFlowOut ( _, node , false ) and
564
+ fwdFlowOut ( _, _ , node , false ) and
565
565
cc = false
566
566
or
567
567
// flow through a callable
568
- exists ( DataFlowCall call |
569
- fwdFlowOutFromArg ( call , node ) and
570
- fwdFlowIsEntered ( call , cc )
568
+ exists ( DataFlowCall call , ReturnKindExtOption kind , ReturnKindExtOption disallowReturnKind |
569
+ fwdFlowOutFromArg ( call , kind , node ) and
570
+ fwdFlowIsEntered ( call , disallowReturnKind , cc ) and
571
+ kind != disallowReturnKind
571
572
)
572
573
}
573
574
@@ -593,11 +594,25 @@ module MakeImpl<LocationSig Location, InputSig<Location> Lang> {
593
594
)
594
595
}
595
596
597
+ pragma [ nomagic]
598
+ private ReturnKindExtOption getDisallowedReturnKind ( ParamNodeEx p ) {
599
+ if allowParameterReturnInSelfEx ( p )
600
+ then result .isNone ( )
601
+ else p .isParameterOf ( _, result .asSome ( ) .( ParamUpdateReturnKind ) .getPosition ( ) )
602
+ }
603
+
596
604
/**
597
605
* Holds if an argument to `call` is reached in the flow covered by `fwdFlow`.
598
606
*/
599
607
pragma [ nomagic]
600
- private predicate fwdFlowIsEntered ( DataFlowCall call , Cc cc ) { fwdFlowIn ( call , _, cc , _) }
608
+ private predicate fwdFlowIsEntered (
609
+ DataFlowCall call , ReturnKindExtOption disallowReturnKind , Cc cc
610
+ ) {
611
+ exists ( ParamNodeEx p |
612
+ fwdFlowIn ( call , _, cc , p ) and
613
+ disallowReturnKind = getDisallowedReturnKind ( p )
614
+ )
615
+ }
601
616
602
617
pragma [ nomagic]
603
618
private predicate fwdFlowInReducedViableImplInSomeCallContext (
@@ -618,7 +633,7 @@ module MakeImpl<LocationSig Location, InputSig<Location> Lang> {
618
633
pragma [ nomagic]
619
634
private DataFlowCallable viableImplInSomeFwdFlowCallContextExt ( DataFlowCall call ) {
620
635
exists ( DataFlowCall ctx |
621
- fwdFlowIsEntered ( ctx , _) and
636
+ fwdFlowIsEntered ( ctx , _, _ ) and
622
637
result = viableImplInCallContextExt ( call , ctx )
623
638
)
624
639
}
@@ -666,17 +681,18 @@ module MakeImpl<LocationSig Location, InputSig<Location> Lang> {
666
681
667
682
// inline to reduce the number of iterations
668
683
pragma [ inline]
669
- private predicate fwdFlowOut ( DataFlowCall call , NodeEx out , Cc cc ) {
684
+ private predicate fwdFlowOut ( DataFlowCall call , ReturnKindExt kind , NodeEx out , Cc cc ) {
670
685
exists ( ReturnPosition pos |
671
686
fwdFlowReturnPosition ( pos , cc ) and
672
687
viableReturnPosOutEx ( call , pos , out ) and
673
- not fullBarrier ( out )
688
+ not fullBarrier ( out ) and
689
+ kind = pos .getKind ( )
674
690
)
675
691
}
676
692
677
693
pragma [ nomagic]
678
- private predicate fwdFlowOutFromArg ( DataFlowCall call , NodeEx out ) {
679
- fwdFlowOut ( call , out , true )
694
+ private predicate fwdFlowOutFromArg ( DataFlowCall call , ReturnKindExtOption kind , NodeEx out ) {
695
+ fwdFlowOut ( call , kind . asSome ( ) , out , true )
680
696
}
681
697
682
698
private predicate stateStepFwd ( FlowState state1 , FlowState state2 ) {
@@ -750,7 +766,7 @@ module MakeImpl<LocationSig Location, InputSig<Location> Lang> {
750
766
)
751
767
or
752
768
// flow into a callable
753
- revFlowIn ( _, node , false ) and
769
+ revFlowIn ( _, _ , node , false ) and
754
770
toReturn = false
755
771
or
756
772
// flow out of a callable
@@ -761,9 +777,10 @@ module MakeImpl<LocationSig Location, InputSig<Location> Lang> {
761
777
)
762
778
or
763
779
// flow through a callable
764
- exists ( DataFlowCall call |
765
- revFlowInToReturn ( call , node ) and
766
- revFlowIsReturned ( call , toReturn )
780
+ exists ( DataFlowCall call , ReturnKindExtOption kind , ReturnKindExtOption disallowReturnKind |
781
+ revFlowIsReturned ( call , kind , toReturn ) and
782
+ revFlowInToReturn ( call , disallowReturnKind , node ) and
783
+ kind != disallowReturnKind
767
784
)
768
785
}
769
786
@@ -824,16 +841,19 @@ module MakeImpl<LocationSig Location, InputSig<Location> Lang> {
824
841
825
842
// inline to reduce the number of iterations
826
843
pragma [ inline]
827
- private predicate revFlowIn ( DataFlowCall call , ArgNodeEx arg , boolean toReturn ) {
828
- exists ( ParamNodeEx p |
829
- revFlow ( p , toReturn ) and
830
- viableParamArgNodeCandFwd1 ( call , p , arg )
831
- )
844
+ private predicate revFlowIn ( DataFlowCall call , ParamNodeEx p , ArgNodeEx arg , boolean toReturn ) {
845
+ revFlow ( p , toReturn ) and
846
+ viableParamArgNodeCandFwd1 ( call , p , arg )
832
847
}
833
848
834
849
pragma [ nomagic]
835
- private predicate revFlowInToReturn ( DataFlowCall call , ArgNodeEx arg ) {
836
- revFlowIn ( call , arg , true )
850
+ private predicate revFlowInToReturn (
851
+ DataFlowCall call , ReturnKindExtOption disallowReturnKind , ArgNodeEx arg
852
+ ) {
853
+ exists ( ParamNodeEx p |
854
+ revFlowIn ( call , p , arg , true ) and
855
+ disallowReturnKind = getDisallowedReturnKind ( p )
856
+ )
837
857
}
838
858
839
859
/**
@@ -842,10 +862,12 @@ module MakeImpl<LocationSig Location, InputSig<Location> Lang> {
842
862
* reaching an argument of `call`.
843
863
*/
844
864
pragma [ nomagic]
845
- private predicate revFlowIsReturned ( DataFlowCall call , boolean toReturn ) {
865
+ private predicate revFlowIsReturned (
866
+ DataFlowCall call , ReturnKindExtOption kind , boolean toReturn
867
+ ) {
846
868
exists ( NodeEx out |
847
869
revFlow ( out , toReturn ) and
848
- fwdFlowOutFromArg ( call , out )
870
+ fwdFlowOutFromArg ( call , kind , out )
849
871
)
850
872
}
851
873
@@ -941,10 +963,14 @@ module MakeImpl<LocationSig Location, InputSig<Location> Lang> {
941
963
942
964
pragma [ nomagic]
943
965
predicate callMayFlowThroughRev ( DataFlowCall call ) {
944
- exists ( ArgNodeEx arg , boolean toReturn |
945
- revFlow ( arg , toReturn ) and
946
- revFlowInToReturn ( call , arg ) and
947
- revFlowIsReturned ( call , toReturn )
966
+ exists (
967
+ ArgNodeEx arg , ReturnKindExtOption kind , ReturnKindExtOption disallowReturnKind ,
968
+ boolean toReturn
969
+ |
970
+ revFlow ( arg , pragma [ only_bind_into ] ( toReturn ) ) and
971
+ revFlowIsReturned ( call , kind , pragma [ only_bind_into ] ( toReturn ) ) and
972
+ revFlowInToReturn ( call , disallowReturnKind , arg ) and
973
+ kind != disallowReturnKind
948
974
)
949
975
}
950
976
0 commit comments