Skip to content

Commit 27519ce

Browse files
authored
Create IfStatementAdditionOverflow.qhelp
1 parent 187299f commit 27519ce

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<!DOCTYPE qhelp PUBLIC
2+
"-//Semmle//qhelp//EN"
3+
"qhelp.dtd">
4+
<qhelp>
5+
6+
<overview>
7+
<p>
8+
Detects <code>if (a+b>c) a=c-b</code>, which incorrectly implements
9+
<code>a = min(a,c-b)</code> if <code>a+b</code> overflows.
10+
</p>
11+
<p>
12+
Also detects variants such as <code>if (b+a>c) a=c-b</code> (swapped
13+
terms in addition), <code>if (a+b>c) { a=c-b }</code> (assignment
14+
inside block), <code>c&lt;a+b</code> (swapped operands), and
15+
<code>&gt;=</code>, <code>&lt;</code>, <code>&lt;=</code> instead of
16+
<code>&gt;</code> (all operators).
17+
</p>
18+
<p>
19+
This integer overflow is the root cause of the buffer overflow in
20+
the SHA-3 reference implementation (CVE-2022-37454).
21+
</p>
22+
</overview>
23+
<recommendation>
24+
<p>
25+
Replace by <code>if (a>c-b) a=c-b</code>. This avoids the overflow
26+
and makes it easy to see that <code>a = min(a,c-b)</code>.
27+
</p>
28+
</recommendation>
29+
<references>
30+
<li>CVE-2022-37454: <a href="https://nvd.nist.gov/vuln/detail/CVE-2022-37454">The Keccak XKCP SHA-3 reference implementation before fdc6fef has an integer overflow and resultant buffer overflow that allows attackers to execute arbitrary code or eliminate expected cryptographic properties. This occurs in the sponge function interface.</a></li>
31+
<li>GitHub Advisory Database: <a href="https://github.com/advisories/GHSA-6w4m-2xhg-2658">CVE-2022-37454: Buffer overflow in sponge queue functions</a></li>
32+
</references>
33+
</qhelp>

0 commit comments

Comments
 (0)