|
1 | 1 | /**
|
2 | 2 | * @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). |
6 | 11 | * @kind problem
|
7 | 12 | * @problem.severity warning
|
8 | 13 | * @id cpp/if-statement-addition-overflow
|
@@ -34,4 +39,4 @@ where ifstmt.getCondition() = relop and
|
34 | 39 | (hashCons(addexpr.getRightOperand()) = hashCons(assignexpr.getLValue()) and
|
35 | 40 | globalValueNumber(addexpr.getLeftOperand()) = globalValueNumber(subexpr.getRightOperand()))) and
|
36 | 41 | 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