Skip to content

Let identity statements be the start point of a method - #348

Merged
swissiety merged 3 commits into
secure-software-engineering:developfrom
Hazem-Gamall:fix/identity-stmts-as-start-points
Nov 30, 2026
Merged

swissiety merged 3 commits into
secure-software-engineering:developfrom
Hazem-Gamall:fix/identity-stmts-as-start-points

Conversation

@Hazem-Gamall

@Hazem-Gamall Hazem-Gamall commented Nov 4, 2026 •

Copy link
Copy Markdown
Member

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 dropped this := @this and p0 := @parameter0, so every body needed a leading nop to 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 nop is one, and so is an identity statement: it defines this or a parameter, exactly what the call and return flows map. Now only @caughtexception heads are dropped, and the pre-transformers (BoomerangPreInterceptor, BoomerangPretransformer, Opal's NopTransformer) add the leading nop only 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, SootScopeTest and OpalControlFlowGraphTest check the start points of a method with a handler (fails on develop) and the leading nop after the pre-transformer; StartPointTest covers a static method that starts with a call (fails without the nop). Test suites: 511 passing with the Soot and SootUp setups and 509 with Opal, 0 regressed (the Soot setup's 3 IteratorHasNextTest failures are on develop too); without any leading nop, StartPointTest and StaticFieldFlowsTest#doubleUnbalancedSingleton fail. API_ASSIST on SootUp (654 tests): unchanged.

@Hazem-Gamall
Hazem-Gamall marked this pull request as draft November 4, 2026 14:43
…and only bodies without them get the leading nop
@swissiety

swissiety commented Nov 13, 2026 •

Copy link
Copy Markdown
Member

Context

the 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:

  • Forward: stepping from (x, a) to (a, b) applies a, via normalFlow using nextEdge.getStart() (DefaultForwardFlowFunction.java:114).
  • Backward: stepping from (b, c) to (a, b) applies b, via nextEdge.getTarget() (DefaultBackwardFlowFunction.java:114). Predecessors come from getPredsOf(start) (BackwardBoomerangSolver.java:191-193).
  • Callee entry: both solvers enter a callee on the self-edge new Edge(sp, sp) (ForwardBoomerangSolver.java:314, BackwardBoomerangSolver.java:343).
  • Backward exit: computeSuccessor sends the fact to returnFlow when edge.getStart() is an exit, and for the backward ICFG the start point counts as an exit (BackwardBoomerangSolver.java:171-173).

1. Start point: why raw Jimple breaks

The 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 := @this, an IdentityStmt. It isn't an AssignStmt (JimpleStatement.java:123), so skipping it loses nothing. Methods whose first statement does real work are not safe:

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
(WeightedBoomerang.java:182, 563).

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 breaks

Jimple 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
the two successors to be distinct. One example is killAtIfStmt(value, succ), called iner.java:66-68: on the fall-through of if x == null goto L, x is known non-null, so null facts can be dropped. The same distinction matters when IDEal/typestate weights or path tracking attach to branch edges.

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 breaks

Jimple 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:

  • A backward query on a callee parameter maps to the argument at the call site. If thall, there is no local and no assignment edge where the value is created, so the queryfinds no allocation.
  • A forward query needs a seed edge (v = const, succ), which doesn't exist either.

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 breaks

The 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 │
│ Entry statement has no effect and no predecessors │ First statement is a real assignop │
│ Each branch has its own edge │ if target == fall-through; targer the if and before its target │
│ Values are locals; allocations are assignments │ Constant operands (foo(5), returerN = const │
│ Every value has an allocation site │ Implicit null field initialisatithis.f = null │

@Hazem-Gamall

Copy link
Copy Markdown
Member Author

tokens haven't been exhausted yet for the week

@Hazem-Gamall

Copy link
Copy Markdown
Member Author

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.

@swissiety
swissiety enabled auto-merge November 30, 2026 10:23
@swissiety
swissiety merged commit ed42a68 into secure-software-engineering:develop Nov 30, 2026
9 checks passed
Comment on lines +77 to +79
// 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

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if the first Stmt is e.g. an AssignStmt I think the Nop is still needed to track the assignment

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants