Repository navigation
Conversation
…eading nop only to bodies without them
…and only bodies without them get the leading nop
Contextthe solver keys every fact to a CFG edge (a, b) and assumes method entries, branches and allocation sites look a certain way. Soot's Jimple breaks those assumptions in four places, which is why the pretransformer exists. How the solver uses edges A fact lives on an edge (a, b). Which statement's effect gets applied depends on direction:
1. Start point: why raw Jimple breaksThe backward solver needs a statement (pred, sp) to apply sp's effect. The first statement has no predecessor, so that edge never exists. When the fact reaches (sp, s2), sp counts as an exit and goes straight to returnFlow, which maps parameters to arguments. sp itself is never executed backward. Instance methods are safe by accident: Jimple starts them with r0 := static A make() {
$r0 = new A; // sp — the allocation site
specialinvoke $r0.<init>();
return $r0;
}A backward query on the returned $r0 walks up to (sp, ), sees that sp is an exitt never processes $r0 = new A, so the allocation site is missed. Same problem with a loop head as the first statement, e.g. static void m(){ while(..){n sp has predecessors through the back-edge, but it is classified as an exit, so ittakes returnFlow and the back-edge is never followed backward. The forward direction has a smaller inconsistency. A node (sp, sp) means "before sp", yet hooks that inspect node.stmt().getStart() read it as "after sp". Examples are the field-load and field-store POIs Nop fix: the entry becomes a statement with no predecessors and no effect. Every real first one, then has a real predecessor edge (nop, stmt1) and goes through normal flow in both directions. 2. if statements: why raw Jimple breaksJimple can produce an if whose target is also its fall-through, as in if c goto L; L: ... with an empty then-branch. Both branches then collapse onto the single edge (if, L). Branch-sensitive logic needs Nop fix: one nop after the if, plus a nop in front of the target with the if retargeted to it. Each branch always has its own successor statement and edge, and the target's join point stays separate. Caveat: the body of killAtIfStmt I saw in JimpleStatement is commented out, so this pruning looks inactive right now. This part is my reading of the design, not documented behaviour. 3. Constants: why raw Jimple breaksJimple allows constants as direct operands: o.f = 5, foo(null), return "x". Soot's jb copy propagation also folds $i0 = 5; foo($i0) into foo(5). Boomerang, though, only tracks Val locals and recognises allocation sites as assignments of the form v = new/const:
Fix: pull each constant into varReplacerN = const placed just before its use. Back-proropagateSourceLineTags) undoes the line shift that copy propagation introduced. 4. Constructor fields: why raw Jimple breaksThe JVM zero-initialises fields implicitly, so the bytecode contains no this.f = null ver writes. A query on o.f then has no allocation site to find. Fix: insert an explicitnull write, tagged UninitializedField. Summary│ Assumption │ Raw Jimple violation | Pretransformer Fix │ |
|
tokens haven't been exhausted yet for the week |
|
What's the plan in light of these uses of the interceptors? should we try to deprecate the bodyInterceptors and instead make those fixes in the SootUp Jimple via standardized interceptors? I personally think the changes necessary for boomerang such as constant unfolding and others are very specific to the boomerang use case and would make sense if they stay a boomerang specific interceptor, especially that this behavior is also in Soot, Opal and SootUp. |
ed42a68
into
secure-software-engineering:develop
| // Initial nop statement, only for bodies that do not start with their identity stmts (static | ||
| // methods without parameters): the backward analysis steps through a statement, e.g. into a | ||
| // callee, only on the edge from its predecessor, so a first statement needs one |
There was a problem hiding this comment.
if the first Stmt is e.g. an AssignStmt I think the Nop is still needed to track the assignment
All three scopes dropped every identity statement among a graph's entry points, to keep exception handlers (
$e := @caughtexception) from becoming start points. That also droppedthis := @thisandp0 := @parameter0, so every body needed a leadingnopto have a start point at all. Without it, a call cannot enter the method.A method's start point is the checkpoint where the state is carried over between caller and callee, so it must be a statement that changes nothing the analysis tracks. A
nopis one, and so is an identity statement: it definesthisor a parameter, exactly what the call and return flows map. Now only@caughtexceptionheads are dropped, and the pre-transformers (BoomerangPreInterceptor,BoomerangPretransformer, Opal'sNopTransformer) add the leadingnoponly to bodies that do not start with an identity statement, i.e. static methods without parameters. Such a body still needs it: backward, the analysis steps through a statement (e.g. into a callee) only on the edge from its predecessor, so a static method that starts with a call loses the value without it. Bodies keep their identity statements first, which lets SootUp rely on that order.Tests:
SootUpScopeTest,SootScopeTestandOpalControlFlowGraphTestcheck the start points of a method with a handler (fails ondevelop) and the leadingnopafter the pre-transformer;StartPointTestcovers a static method that starts with a call (fails without thenop). Test suites: 511 passing with the Soot and SootUp setups and 509 with Opal, 0 regressed (the Soot setup's 3IteratorHasNextTestfailures are ondeveloptoo); without any leadingnop,StartPointTestandStaticFieldFlowsTest#doubleUnbalancedSingletonfail. API_ASSIST on SootUp (654 tests): unchanged.