Skip to content

Commit dc09c92

Browse files
authored
Update IfStatementAdditionOverflow.ql
1 parent 08f04d5 commit dc09c92

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

cpp/ql/src/experimental/Security/CWE/CWE-190/IfStatementAdditionOverflow.ql

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
11
/**
22
* @name Integer addition may overflow inside if statement
3-
* @description "if (a+b>c) a=c-b" was detected where "a+b" may potentially
4-
* produce an integer overflow (or wraparound). The code can be
5-
* rewritten to "if (a>c-b) a=c-b" which avoids the overflow.
3+
* @description Detects "if (a+b>c) a=c-b", which incorrectly implements
4+
* a = min(a,c-b) if a+b overflows. Should be replaced by
5+
* "if (a>c-b) a=c-b". Also detects "if (b+a>c) a=c-b"
6+
* (swapped terms in addition), if (a+b>c) { a=c-b }"
7+
* (assignment inside block), "c<a+b" (swapped operands) and
8+
* ">=", "<", "<=" instead of ">" (all operators). This
9+
* integer overflow is the root cause of the buffer overflow
10+
* in the SHA-3 reference implementation (CVE-2022-37454).
611
* @kind problem
712
* @problem.severity warning
813
* @id cpp/if-statement-addition-overflow
@@ -34,4 +39,4 @@ where ifstmt.getCondition() = relop and
3439
(hashCons(addexpr.getRightOperand()) = hashCons(assignexpr.getLValue()) and
3540
globalValueNumber(addexpr.getLeftOperand()) = globalValueNumber(subexpr.getRightOperand()))) and
3641
globalValueNumber(relop.getAnOperand()) = globalValueNumber(subexpr.getLeftOperand())
37-
select ifstmt, "Integer addition may overflow inside if statement."
42+
select ifstmt, "\"if (a+b>c) a=c-b\" was detected where the $@ may potentially overflow/wraparound. The code can be rewritten as \"if (a>c-b) a=c-b\" which avoids the overflow.", addexpr, "addition"

0 commit comments

Comments
 (0)