Skip to content

Commit 79fa79a

Browse files
committed
C++: Fix join order problem in TaintedAllocationSize
1 parent 5bfd22e commit 79fa79a

File tree

2 files changed

+15
-9
lines changed

2 files changed

+15
-9
lines changed

cpp/ql/lib/semmle/code/cpp/controlflow/IRGuards.qll

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -685,6 +685,12 @@ class IRGuardCondition extends Instruction {
685685
unary_compares_eq(valueNumber(this), op, k, areEqual, value)
686686
}
687687

688+
bindingset[block, value]
689+
pragma[inline_late]
690+
private predicate ensuresEqvalueControls(IRBlock block, AbstractValue value) {
691+
this.valueControls(block, value)
692+
}
693+
688694
/**
689695
* Holds if (determined by this guard) `left == right + k` must be `areEqual` in `block`.
690696
* If `areEqual = false` then this implies `left != right + k`.
@@ -693,7 +699,7 @@ class IRGuardCondition extends Instruction {
693699
predicate ensuresEq(Operand left, Operand right, int k, IRBlock block, boolean areEqual) {
694700
exists(AbstractValue value |
695701
compares_eq(valueNumber(this), left, right, k, areEqual, value) and
696-
this.valueControls(block, value)
702+
this.ensuresEqvalueControls(block, value)
697703
)
698704
}
699705

cpp/ql/src/Security/CWE/CWE-190/TaintedAllocationSize.ql

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,13 @@ predicate hasUpperBoundsCheck(Variable var) {
4646
)
4747
}
4848

49-
predicate nodeIsBarrierEqualityCandidate(DataFlow::Node node, Operand access, Variable checkedVar) {
50-
exists(Instruction instr | instr = node.asOperand().getDef() |
51-
readsVariable(instr, checkedVar) and
52-
any(IRGuardCondition guard).ensuresEq(access, _, _, instr.getBlock(), true)
49+
predicate nodeHasBarrierEquality(DataFlow::Node node) {
50+
exists(Variable checkedVar, Operand access |
51+
readsVariable(access.getDef(), checkedVar) and
52+
exists(Instruction instr | instr = node.asOperand().getDef() |
53+
readsVariable(pragma[only_bind_into](instr), pragma[only_bind_into](checkedVar)) and
54+
any(IRGuardCondition guard).ensuresEq(access, _, _, instr.getBlock(), true)
55+
)
5356
)
5457
}
5558

@@ -76,10 +79,7 @@ module TaintedAllocationSizeConfig implements DataFlow::ConfigSig {
7679
hasUpperBoundsCheck(checkedVar)
7780
)
7881
or
79-
exists(Variable checkedVar, Operand access |
80-
readsVariable(access.getDef(), checkedVar) and
81-
nodeIsBarrierEqualityCandidate(node, access, checkedVar)
82-
)
82+
nodeHasBarrierEquality(node)
8383
or
8484
// block flow to inside of identified allocation functions (this flow leads
8585
// to duplicate results)

0 commit comments

Comments
 (0)