Skip to content

Commit 61a012f

Browse files
committed
C++: Don't allow 'x < 0' as a barrier guard.
1 parent c883aa0 commit 61a012f

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

cpp/ql/src/Security/CWE/CWE-129/ImproperArrayIndexValidation.ql

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,11 @@ predicate isFlowSource(FS::FlowSource source, string sourceType) {
2525

2626
predicate guardChecks(IRGuardCondition g, Expr e, boolean branch) {
2727
exists(Operand op | op.getDef().getConvertedResultExpression() = e |
28-
// op < k
29-
g.comparesLt(op, _, true, any(BooleanValue bv | bv.getValue() = branch))
28+
// `op < k` is true and `k > 0`
29+
g.comparesLt(op, any(int k | k > 0), true, any(BooleanValue bv | bv.getValue() = branch))
3030
or
31-
// op < _ + k
32-
g.comparesLt(op, _, _, true, branch)
31+
// `op < _ + k` is true and `k > 0`.
32+
g.comparesLt(op, _, any(int k | k > 0), true, branch)
3333
or
3434
// op == k
3535
g.comparesEq(op, _, true, any(BooleanValue bv | bv.getValue() = branch))

0 commit comments

Comments
 (0)