@@ -557,17 +557,18 @@ module MakeImpl<LocationSig Location, InputSig<Location> Lang> {
557
557
)
558
558
or
559
559
// flow into a callable
560
- fwdFlowIn ( _, _ , _, node ) and
560
+ fwdFlowInParam ( _, node , _) and
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,30 @@ module MakeImpl<LocationSig Location, InputSig<Location> Lang> {
593
594
)
594
595
}
595
596
597
+ pragma [ nomagic]
598
+ private predicate fwdFlowInParam ( DataFlowCall call , ParamNodeEx p , Cc cc ) {
599
+ fwdFlowIn ( call , _, cc , p )
600
+ }
601
+
602
+ pragma [ nomagic]
603
+ private ReturnKindExtOption getDisallowedReturnKind ( ParamNodeEx p ) {
604
+ if allowParameterReturnInSelfEx ( p )
605
+ then result .isNone ( )
606
+ else p .isParameterOf ( _, result .asSome ( ) .( ParamUpdateReturnKind ) .getPosition ( ) )
607
+ }
608
+
596
609
/**
597
610
* Holds if an argument to `call` is reached in the flow covered by `fwdFlow`.
598
611
*/
599
612
pragma [ nomagic]
600
- private predicate fwdFlowIsEntered ( DataFlowCall call , Cc cc ) { fwdFlowIn ( call , _, cc , _) }
613
+ private predicate fwdFlowIsEntered (
614
+ DataFlowCall call , ReturnKindExtOption disallowReturnKind , Cc cc
615
+ ) {
616
+ exists ( ParamNodeEx p |
617
+ fwdFlowInParam ( call , p , cc ) and
618
+ disallowReturnKind = getDisallowedReturnKind ( p )
619
+ )
620
+ }
601
621
602
622
pragma [ nomagic]
603
623
private predicate fwdFlowInReducedViableImplInSomeCallContext (
@@ -618,7 +638,7 @@ module MakeImpl<LocationSig Location, InputSig<Location> Lang> {
618
638
pragma [ nomagic]
619
639
private DataFlowCallable viableImplInSomeFwdFlowCallContextExt ( DataFlowCall call ) {
620
640
exists ( DataFlowCall ctx |
621
- fwdFlowIsEntered ( ctx , _) and
641
+ fwdFlowIsEntered ( ctx , _, _ ) and
622
642
result = viableImplInCallContextExt ( call , ctx )
623
643
)
624
644
}
@@ -666,17 +686,18 @@ module MakeImpl<LocationSig Location, InputSig<Location> Lang> {
666
686
667
687
// inline to reduce the number of iterations
668
688
pragma [ inline]
669
- private predicate fwdFlowOut ( DataFlowCall call , NodeEx out , Cc cc ) {
670
- exists ( ReturnPosition pos |
671
- fwdFlowReturnPosition ( pos , cc ) and
672
- viableReturnPosOutEx ( call , pos , out ) and
673
- not fullBarrier ( out )
674
- )
689
+ private predicate fwdFlowOut ( DataFlowCall call , ReturnPosition pos , NodeEx out , Cc cc ) {
690
+ fwdFlowReturnPosition ( pos , cc ) and
691
+ viableReturnPosOutEx ( call , pos , out ) and
692
+ not fullBarrier ( out )
675
693
}
676
694
677
695
pragma [ nomagic]
678
- private predicate fwdFlowOutFromArg ( DataFlowCall call , NodeEx out ) {
679
- fwdFlowOut ( call , out , true )
696
+ private predicate fwdFlowOutFromArg ( DataFlowCall call , ReturnKindExtOption kind , NodeEx out ) {
697
+ exists ( ReturnPosition pos |
698
+ fwdFlowOut ( call , pos , out , true ) and
699
+ kind .asSome ( ) = pos .getKind ( )
700
+ )
680
701
}
681
702
682
703
private predicate stateStepFwd ( FlowState state1 , FlowState state2 ) {
@@ -750,7 +771,7 @@ module MakeImpl<LocationSig Location, InputSig<Location> Lang> {
750
771
)
751
772
or
752
773
// flow into a callable
753
- revFlowIn ( _, node , false ) and
774
+ revFlowIn ( _, _ , node , false ) and
754
775
toReturn = false
755
776
or
756
777
// flow out of a callable
@@ -761,9 +782,10 @@ module MakeImpl<LocationSig Location, InputSig<Location> Lang> {
761
782
)
762
783
or
763
784
// flow through a callable
764
- exists ( DataFlowCall call |
765
- revFlowInToReturn ( call , node ) and
766
- revFlowIsReturned ( call , toReturn )
785
+ exists ( DataFlowCall call , ReturnKindExtOption kind , ReturnKindExtOption disallowReturnKind |
786
+ revFlowIsReturned ( call , kind , toReturn ) and
787
+ revFlowInToReturn ( call , disallowReturnKind , node ) and
788
+ kind != disallowReturnKind
767
789
)
768
790
}
769
791
@@ -824,16 +846,19 @@ module MakeImpl<LocationSig Location, InputSig<Location> Lang> {
824
846
825
847
// inline to reduce the number of iterations
826
848
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
- )
849
+ private predicate revFlowIn ( DataFlowCall call , ParamNodeEx p , ArgNodeEx arg , boolean toReturn ) {
850
+ revFlow ( p , toReturn ) and
851
+ viableParamArgNodeCandFwd1 ( call , p , arg )
832
852
}
833
853
834
854
pragma [ nomagic]
835
- private predicate revFlowInToReturn ( DataFlowCall call , ArgNodeEx arg ) {
836
- revFlowIn ( call , arg , true )
855
+ private predicate revFlowInToReturn (
856
+ DataFlowCall call , ReturnKindExtOption disallowReturnKind , ArgNodeEx arg
857
+ ) {
858
+ exists ( ParamNodeEx p |
859
+ revFlowIn ( call , p , arg , true ) and
860
+ disallowReturnKind = getDisallowedReturnKind ( p )
861
+ )
837
862
}
838
863
839
864
/**
@@ -842,10 +867,12 @@ module MakeImpl<LocationSig Location, InputSig<Location> Lang> {
842
867
* reaching an argument of `call`.
843
868
*/
844
869
pragma [ nomagic]
845
- private predicate revFlowIsReturned ( DataFlowCall call , boolean toReturn ) {
870
+ private predicate revFlowIsReturned (
871
+ DataFlowCall call , ReturnKindExtOption kind , boolean toReturn
872
+ ) {
846
873
exists ( NodeEx out |
847
874
revFlow ( out , toReturn ) and
848
- fwdFlowOutFromArg ( call , out )
875
+ fwdFlowOutFromArg ( call , kind , out )
849
876
)
850
877
}
851
878
@@ -947,10 +974,14 @@ module MakeImpl<LocationSig Location, InputSig<Location> Lang> {
947
974
948
975
pragma [ nomagic]
949
976
predicate callMayFlowThroughRev ( DataFlowCall call ) {
950
- exists ( ArgNodeEx arg , boolean toReturn |
951
- revFlow ( arg , toReturn ) and
952
- revFlowInToReturn ( call , arg ) and
953
- revFlowIsReturned ( call , toReturn )
977
+ exists (
978
+ ArgNodeEx arg , ReturnKindExtOption kind , ReturnKindExtOption disallowReturnKind ,
979
+ boolean toReturn
980
+ |
981
+ revFlow ( arg , pragma [ only_bind_into ] ( toReturn ) ) and
982
+ revFlowIsReturned ( call , kind , pragma [ only_bind_into ] ( toReturn ) ) and
983
+ revFlowInToReturn ( call , disallowReturnKind , arg ) and
984
+ kind != disallowReturnKind
954
985
)
955
986
}
956
987
0 commit comments