Skip to content

Commit 4ab6767

Browse files
committed
C++: Add qhelp to new query.
1 parent 769ff5c commit 4ab6767

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
int f(char * s, unsigned size) {
2+
char* buf = (char*)malloc(size);
3+
4+
strncpy(buf, s, size + 1); // wrong: copy may exceed size of buf
5+
6+
for (int i = 0; i <= size; i++) { // wrong: upper limit that is higher than size of buf
7+
cout << buf[i];
8+
}
9+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<!DOCTYPE qhelp PUBLIC
2+
"-//Semmle//qhelp//EN"
3+
"qhelp.dtd">
4+
<qhelp>
5+
<overview>
6+
<p>You must ensure that you do not exceed the size of an allocation during write and read operations.
7+
If an operation attempts to write to or access an element that is outside the range of the allocation then this results in a buffer overflow.
8+
Buffer overflows can lead to anything from a segmentation fault to a security vulnerability.
9+
</p>
10+
11+
</overview>
12+
<recommendation>
13+
<p>
14+
Check the offsets and sizes used in the highlighted operations to ensure that a buffer overflow will not occur.
15+
</p>
16+
17+
</recommendation>
18+
<example><sample src="OverrunWriteProductFlow.cpp" />
19+
20+
21+
22+
</example>
23+
<references>
24+
25+
<li>I. Gerg. <em>An Overview and Example of the Buffer-Overflow Exploit</em>. IANewsletter vol 7 no 4. 2005.</li>
26+
<li>M. Donaldson. <em>Inside the Buffer Overflow Attack: Mechanism, Method &amp; Prevention</em>. SANS Institute InfoSec Reading Room. 2002.</li>
27+
28+
</references>
29+
</qhelp>

0 commit comments

Comments
 (0)