Skip to content

Commit 859fcdb

Browse files
committed
Binary/CIL: Fix enclosing callable of branch target.
1 parent 0f6c0e0 commit 859fcdb

3 files changed

Lines changed: 24 additions & 0 deletions

File tree

binary/ql/lib/semmle/code/binary/ast/internal/CilInstructions.qll

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -366,6 +366,7 @@ abstract class CilBranchInstruction extends CilInstruction {
366366
CilInstruction getABranchTarget() {
367367
exists(CilMethod m, int delta |
368368
il_branch_target(this, delta) and
369+
this.getEnclosingMethod() = m and
369370
hasMethodAndOffset(m, delta, result)
370371
)
371372
}

binary/ql/lib/semmle/code/binary/ast/ir/internal/Consistency.qll

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,16 @@ module StagedConsistencyInput<InstructionSig Input> {
2828
exists(i.getAPredecessor()) and
2929
not exists(i.getASuccessor())
3030
}
31+
32+
query predicate nonLocalSuccessor(Input::Function f1, Input::Function f2, Input::Instruction i, SuccessorType t) {
33+
i.getEnclosingFunction() = f1 and
34+
i.getSuccessor(t).getEnclosingFunction() = f2 and
35+
f1 != f2
36+
}
37+
38+
query predicate successorMissingFunction(Input::Function f, Input::Instruction i1, Input::Instruction i2, SuccessorType t) {
39+
i1.getEnclosingFunction() = f and
40+
i1.getSuccessor(t) = i2 and
41+
not exists(i2.getEnclosingFunction())
42+
}
3143
}

binary/ql/lib/semmle/code/binary/ast/ir/internal/Instruction0/Consistency.ql

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
private import Instruction0
22
import semmle.code.binary.ast.ir.internal.Consistency
3+
private import codeql.controlflow.SuccessorType
34
import StagedConsistencyInput<Instruction0>
45
private import TranslatedInstruction
56
private import TranslatedFunction
@@ -30,3 +31,13 @@ query predicate nonUniqueResultVariable0(
3031
strictcount(ti.getResultVariable()) = k and
3132
k > 1
3233
}
34+
35+
query predicate nonUniqueSuccessor0(
36+
TranslatedFunction tf, InstructionTag tag, TranslatedInstruction ti, string s, SuccessorType t,
37+
int k
38+
) {
39+
tf = ti.getEnclosingFunction() and
40+
s = concat(ti.getAQlClass().toString(), ", ") and
41+
strictcount(ti.getSuccessor(tag, t)) = k and
42+
k > 1
43+
}

0 commit comments

Comments
 (0)