11package soot .jimple .infoflow .problems ;
22
3- import java .util .Arrays ;
4- import java .util .Collection ;
5- import java .util .Collections ;
6- import java .util .HashSet ;
7- import java .util .Set ;
3+ import java .util .*;
84
95import heros .FlowFunction ;
106import heros .FlowFunctions ;
@@ -140,6 +136,7 @@ private Set<Abstraction> computeAliases(final DefinitionStmt defStmt, Abstractio
140136 AccessPath ap = source .getAccessPath ();
141137 Value sourceBase = ap .getPlainValue ();
142138 boolean handoverLeftValue = false ;
139+ boolean leftSideOverwritten = false ;
143140 if (leftOp instanceof StaticFieldRef ) {
144141 if (manager .getConfig ()
145142 .getStaticFieldTrackingMode () != InfoflowConfiguration .StaticFieldTrackingMode .None
@@ -171,11 +168,10 @@ else if (source.dependsOnCutAP() || isCircularType(leftVal)) {
171168 if (handoverLeftValue ) {
172169 // We found a missed path upwards
173170 // inject same stmt in infoflow solver
174- manager .getForwardSolver ()
175- .processEdge (new PathEdge <Unit , Abstraction >(d1 , srcUnit , source .getActiveCopy ()));
171+ handOver (d1 , srcUnit , source );
176172 }
177173
178- boolean leftSideOverwritten = !(leftOp instanceof ArrayRef ) && !(leftOp instanceof FieldRef )
174+ leftSideOverwritten = !(leftOp instanceof ArrayRef ) && !(leftOp instanceof FieldRef )
179175 && Aliasing .baseMatches (leftOp , source );
180176 if (leftSideOverwritten )
181177 return null ;
@@ -203,7 +199,6 @@ else if (source.dependsOnCutAP() || isCircularType(leftVal)) {
203199 .getStaticFieldTrackingMode () != InfoflowConfiguration .StaticFieldTrackingMode .None
204200 && ap .firstFieldMatches (((StaticFieldRef ) rightVal ).getField ())) {
205201 addLeftValue = true ;
206- // leftType = source.getAccessPath().getBaseType();
207202 }
208203 } else if (rightVal instanceof InstanceFieldRef ) {
209204 InstanceFieldRef instRef = (InstanceFieldRef ) rightVal ;
@@ -408,10 +403,9 @@ private Set<Abstraction> computeTargetsInternal(Abstraction d1, Abstraction sour
408403 }
409404 }
410405
411- if (res != null ) {
412- for (Abstraction d3 : res )
413- manager .getForwardSolver ().injectContext (solver , dest , d3 , callSite , source , d1 );
414- }
406+ for (Abstraction d3 : res )
407+ manager .getForwardSolver ().injectContext (solver , dest , d3 , callSite , source , d1 );
408+
415409 return res ;
416410 }
417411 };
@@ -635,8 +629,7 @@ private Set<Abstraction> computeTargetsInternal(Abstraction d1, Abstraction sour
635629
636630 if (taintWrapper != null ) {
637631 if (taintWrapper .isExclusive (callStmt , source )) {
638- manager .getForwardSolver ().processEdge (
639- new PathEdge <Unit , Abstraction >(d1 , callStmt , source .getActiveCopy ()));
632+ handOver (d1 , callSite , source );
640633 }
641634
642635 Set <Abstraction > wrapperAliases = taintWrapper .getAliasesForMethod (callStmt , d1 , source );
@@ -648,8 +641,7 @@ private Set<Abstraction> computeTargetsInternal(Abstraction d1, Abstraction sour
648641 abs .setCorrespondingCallSite (callStmt );
649642
650643 for (Unit u : manager .getICFG ().getPredsOf (callSite ))
651- manager .getForwardSolver ().processEdge (
652- new PathEdge <Unit , Abstraction >(d1 , u , abs .getActiveCopy ()));
644+ handOver (d1 , u , abs );
653645 }
654646 return passOnSet ;
655647 }
@@ -682,8 +674,7 @@ private Set<Abstraction> computeTargetsInternal(Abstraction d1, Abstraction sour
682674 && arg == source .getAccessPath ().getPlainValue ())) {
683675 // non standard source sink manager might need this
684676 if (isSource )
685- manager .getForwardSolver ()
686- .processEdge (new PathEdge <>(d1 , callSite , source .getActiveCopy ()));
677+ handOver (d1 , callSite , source );
687678 return null ;
688679 }
689680 } else {
@@ -694,8 +685,7 @@ private Set<Abstraction> computeTargetsInternal(Abstraction d1, Abstraction sour
694685 // the native stmt does not create a new alias but we notice that we
695686 // missed this argument in the infoflow search.
696687 Abstraction newSource = source .deriveNewAbstractionWithTurnUnit (callSite );
697- manager .getForwardSolver ()
698- .processEdge (new PathEdge <>(d1 , callSite , newSource .getActiveCopy ()));
688+ handOver (d1 , callSite , newSource );
699689 return null ;
700690 }
701691 }
@@ -711,6 +701,27 @@ private boolean isPrimitiveOrStringBase(Abstraction abs) {
711701 return t instanceof PrimType
712702 || (TypeUtils .isStringType (t ) && !abs .getAccessPath ().getCanHaveImmutableAliases ());
713703 }
704+
705+ private void handOver (Abstraction d1 , Unit unit , Abstraction in ) {
706+ in = in .getActiveCopy ();
707+
708+ if (manager .getConfig ().getImplicitFlowMode ().trackControlFlowDependencies ()) {
709+ // We maybe turned around inside a conditional, so we reconstruct the condition
710+ // dominator. Also, we lost track of the dominators in the alias search. Thus,
711+ // we derive interprocedural wildcards.
712+ // See ImplicitTests#conditionalAliasingTest
713+ List <Unit > condUnits = manager .getOriginalICFG ().getConditionalBranchesInterprocedural (unit );
714+ // No condition path -> no need to search for one
715+ for (Unit condUnit : condUnits ) {
716+ Abstraction abs = in .deriveNewAbstractionWithDominator (condUnit );
717+ if (abs != null )
718+ manager .getForwardSolver ().processEdge (new PathEdge <>(d1 , unit , abs ));
719+ }
720+ } else {
721+ manager .getForwardSolver ()
722+ .processEdge (new PathEdge <>(d1 , unit , in ));
723+ }
724+ }
714725 };
715726 }
716727}
0 commit comments