-
Notifications
You must be signed in to change notification settings - Fork 2k
Expand file tree
/
Copy pathImproperNullTermination.qhelp
More file actions
47 lines (35 loc) · 1.39 KB
/
ImproperNullTermination.qhelp
File metadata and controls
47 lines (35 loc) · 1.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
<!DOCTYPE qhelp PUBLIC
"-//Semmle//qhelp//EN"
"qhelp.dtd">
<qhelp>
<overview>
<p> Built-in C string functions such as <code>strcat</code> require that their
input string arguments are null terminated. If the input string arguments are
not null terminated, these functions will read/write beyond the length of the
buffer containing the string, resulting in either buffer over-read or buffer
overflow, respectively.
</p>
</overview>
<recommendation>
<p>
Review the code and consider whether the variable that holds the string should have
an initializer or whether some path through the program fails to null terminate the
string.
</p>
</recommendation>
<example>
<p>The destination variable <code>dest</code> used in the call to <code>strcat</code>
does not (necessarily) contain a null terminator. Consequently, the call to <code>strcat</code>
may result in a buffer overflow.
</p>
<sample src="ImproperNullTerminationBad.cpp" />
<p>In the revised example, <code>dest</code> is properly null terminated before the
the call to <code>strcat</code>.
</p>
<sample src="ImproperNullTerminationGood.cpp" />
</example>
<references>
<li>B. Chess and J. West, <em>Secure Programming with Static Analysis</em>, 6.2 Maintaining the Null Terminator. Addison-Wesley. 2007.</li>
<li>Linux Programmer's Manual: <a href="http://man7.org/linux/man-pages/man3/strncat.3.html">STRCAT(3)</a>.</li>
</references>
</qhelp>