1313import java .util .Collection ;
1414import java .util .Collections ;
1515import java .util .HashSet ;
16+ import java .util .Iterator ;
1617import java .util .Set ;
1718
1819import heros .FlowFunction ;
4950import soot .jimple .infoflow .InfoflowConfiguration .StaticFieldTrackingMode ;
5051import soot .jimple .infoflow .InfoflowManager ;
5152import soot .jimple .infoflow .aliasing .Aliasing ;
53+ import soot .jimple .infoflow .aliasing .IAliasingStrategy ;
5254import soot .jimple .infoflow .callmappers .CallerCalleeManager ;
5355import soot .jimple .infoflow .callmappers .ICallerCalleeArgumentMapper ;
5456import soot .jimple .infoflow .cfg .FlowDroidSinkStatement ;
@@ -130,8 +132,7 @@ private void addTaintViaStmt(final Abstraction d1, final AssignStmt assignStmt,
130132 if (!source .getAccessPath ().isEmpty ()) {
131133 // Special handling for array construction
132134 if (leftValue instanceof ArrayRef && targetType != null ) {
133- ArrayRef arrayRef = (ArrayRef ) leftValue ;
134- targetType = TypeUtils .buildArrayOrAddDimension (targetType , arrayRef .getType ().getArrayType ());
135+ targetType = TypeUtils .buildArrayOrAddDimension (targetType , leftValue .getType ().getArrayType ());
135136 }
136137
137138 // If this is an unrealizable typecast, drop the abstraction
@@ -310,10 +311,11 @@ else if (rightVal instanceof InstanceFieldRef) {
310311 // y = x && x.f tainted --> y.f, x.f tainted
311312 // y.g = x && x.f tainted --> y.g.f, x.f tainted
312313 else if (rightVal instanceof Local && newSource .getAccessPath ().isInstanceFieldRef ()) {
313- Local base = newSource .getAccessPath ().getPlainValue ();
314+ AccessPath ap = newSource .getAccessPath ();
315+ Local base = ap .getPlainValue ();
314316 if (aliasing .mayAlias (rightVal , base )) {
315317 addLeftValue = true ;
316- targetType = newSource . getAccessPath () .getBaseType ();
318+ targetType = ap .getBaseType ();
317319 }
318320 }
319321 // generic case, is true for Locals, ArrayRefs that are
@@ -432,8 +434,9 @@ public FlowFunction<Abstraction> getCallFlowFunction(final Unit src, final SootM
432434 public Set <Abstraction > computeTargets (Abstraction d1 , Abstraction source ) {
433435 Set <Abstraction > res = computeTargetsInternal (d1 , source );
434436 if (res != null && !res .isEmpty () && d1 != null ) {
437+ final IAliasingStrategy strategy = aliasing .getAliasingStrategy ();
435438 for (Abstraction abs : res )
436- aliasing . getAliasingStrategy () .injectCallingContext (abs , solver , dest , src , source , d1 );
439+ strategy .injectCallingContext (abs , solver , dest , src , source , d1 );
437440 }
438441 return notifyOutFlowHandlers (stmt , d1 , source , res , FlowFunctionType .CallFlowFunction );
439442 }
@@ -567,24 +570,24 @@ private Set<Abstraction> computeTargetsInternal(Abstraction source, Abstraction
567570 if (callSite == null )
568571 return null ;
569572
573+ final AccessPath newSourceAP = newSource .getAccessPath ();
570574 // Do we need to retain all the taints?
571- if (aliasing .getAliasingStrategy ().isLazyAnalysis ()
572- && Aliasing .canHaveAliases (newSource .getAccessPath ()))
575+ if (aliasing .getAliasingStrategy ().isLazyAnalysis () && Aliasing .canHaveAliases (newSourceAP ))
573576 res .add (newSource );
574577
575578 // Static fields are handled in a rule
576- if (!newSource . getAccessPath () .isStaticFieldRef () && !callee .isStaticInitializer ()) {
579+ if (!newSourceAP .isStaticFieldRef () && !callee .isStaticInitializer ()) {
577580 // if we have a returnStmt we have to look at the
578581 // returned value:
579582 if (returnStmt != null && callSite instanceof DefinitionStmt ) {
580583 Value retLocal = returnStmt .getOp ();
581584 DefinitionStmt defnStmt = (DefinitionStmt ) callSite ;
582585 Value leftOp = defnStmt .getLeftOp ();
583586
584- if (aliasing .mayAlias (retLocal , newSource . getAccessPath () .getPlainValue ())
587+ if (aliasing .mayAlias (retLocal , newSourceAP .getPlainValue ())
585588 && !isExceptionHandler (retSite )) {
586- AccessPath ap = manager .getAccessPathFactory ()
587- . copyWithNewValue ( newSource . getAccessPath (), leftOp );
589+ AccessPath ap = manager .getAccessPathFactory (). copyWithNewValue ( newSourceAP ,
590+ leftOp );
588591 Abstraction abs = newSource .deriveNewAbstraction (ap , (Stmt ) exitStmt );
589592 if (abs != null ) {
590593 res .add (abs );
@@ -600,7 +603,7 @@ private Set<Abstraction> computeTargetsInternal(Abstraction source, Abstraction
600603 }
601604
602605 // Check parameters
603- Value sourceBase = newSource . getAccessPath () .getPlainValue ();
606+ Value sourceBase = newSourceAP .getPlainValue ();
604607 boolean parameterAliases = false ;
605608 {
606609 Value originalCallArg = null ;
@@ -660,17 +663,16 @@ private Set<Abstraction> computeTargetsInternal(Abstraction source, Abstraction
660663 if (interproceduralCFG ().methodWritesValue (callee , paramLocals [i ]))
661664 continue ;
662665
663- AccessPath ap = manager .getAccessPathFactory ().copyWithNewValue (
664- newSource .getAccessPath (), originalCallArg ,
665- isReflectiveCallSite ? null : newSource .getAccessPath ().getBaseType (),
666- false );
666+ AccessPath ap = manager .getAccessPathFactory ().copyWithNewValue (newSourceAP ,
667+ originalCallArg ,
668+ isReflectiveCallSite ? null : newSourceAP .getBaseType (), false );
667669 Abstraction abs = newSource .deriveNewAbstraction (ap , (Stmt ) exitStmt );
668670
669671 if (abs != null ) {
670672 res .add (abs );
673+ final Aliasing aliasing = manager .getAliasing ();
671674 for (Abstraction callerD1 : callerD1s )
672- manager .getAliasing ().computeAliases (callerD1 , iCallStmt ,
673- originalCallArg , res ,
675+ aliasing .computeAliases (callerD1 , iCallStmt , originalCallArg , res ,
674676 interproceduralCFG ().getMethodOf (callSite ), abs );
675677 }
676678 }
@@ -717,22 +719,28 @@ private Set<Abstraction> computeTargetsInternal(Abstraction source, Abstraction
717719 }
718720 }
719721 }
722+ Iterator <Abstraction > rit = res .iterator ();
723+ if (rit .hasNext ()) {
724+ SootMethod methodOfCallsite = interproceduralCFG ().getMethodOf (callSite );
725+
726+ while (rit .hasNext ()) {
727+ final Abstraction abs = rit .next ();
728+
729+ // Aliases of implicitly tainted variables must be
730+ // mapped back into the caller's context on return
731+ // when we leave the last implicitly-called method
732+ if ((abs .isImplicit () && !callerD1sConditional )
733+ || aliasing .getAliasingStrategy ().requiresAnalysisOnReturn ()) {
734+ for (Abstraction d1 : callerD1s ) {
720735
721- for (Abstraction abs : res ) {
722- // Aliases of implicitly tainted variables must be
723- // mapped back into the caller's context on return
724- // when we leave the last implicitly-called method
725- if ((abs .isImplicit () && !callerD1sConditional )
726- || aliasing .getAliasingStrategy ().requiresAnalysisOnReturn ()) {
727- for (Abstraction d1 : callerD1s ) {
728- aliasing .computeAliases (d1 , iCallStmt , null , res ,
729- interproceduralCFG ().getMethodOf (callSite ), abs );
736+ aliasing .computeAliases (d1 , iCallStmt , null , res , methodOfCallsite , abs );
737+ }
730738 }
731- }
732739
733- // Set the corresponding call site
734- if (abs != newSource ) {
735- abs .setCorrespondingCallSite (iCallStmt );
740+ // Set the corresponding call site
741+ if (abs != newSource ) {
742+ abs .setCorrespondingCallSite (iCallStmt );
743+ }
736744 }
737745 }
738746 return res ;
0 commit comments