You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: cpp/ql/src/Likely Bugs/Memory Management/PotentialBufferOverflow.qhelp
+3-7Lines changed: 3 additions & 7 deletions
Original file line number
Diff line number
Diff line change
@@ -3,13 +3,12 @@
3
3
"qhelp.dtd">
4
4
<qhelp>
5
5
<overview>
6
-
<p>This rule highlights potentially overflowing calls to the functions <code>sprintf</code>, <code>vsprintf</code>, and <code>gets</code> with a warning.
7
-
These functions allow unbounded writes to buffers, which may cause an overflow when used on untrusted data or without adequate checks on the size of the data. Function calls of this type constitute a security risk through buffer overflows. The <code>gets</code> function, in particular,
8
-
is one of the vulnerabilities exploited by the Internet Worm of 1988, one of the first computer worms to spread through the Internet.</p>
6
+
<p>This rule highlights potentially overflowing calls to the functions <code>sprintf</code> and <code>vsprintf</code> with a warning.
7
+
These functions allow unbounded writes to buffers, which may cause an overflow when used on untrusted data or without adequate checks on the size of the data. Function calls of this type constitute a security risk through buffer overflows.
9
8
10
9
</overview>
11
10
<recommendation>
12
-
<p>Always control the length of buffer copy and buffer write operations. Use the safer variants <code>snprintf</code>, <code>vsnprintf</code>, and <code>fgets</code>, which include an extra buffer length argument.</p>
11
+
<p>Always control the length of buffer copy and buffer write operations. Use the safer variants <code>snprintf</code>and <code>vsnprintf</code>, which include an extra buffer length argument.</p>
13
12
14
13
</recommendation>
15
14
<example>
@@ -18,7 +17,6 @@ is one of the vulnerabilities exploited by the Internet Worm of 1988, one of the
18
17
<p>To improve the security of this example code, three changes should be made:</p>
19
18
<ol>
20
19
<li>Introduce a preprocessor define for the size of the buffer.</li>
21
-
<li>Replace the call to <code>gets</code> with <code>fgets</code>, specifying the define as the maximum length to copy. This will prevent the buffer overflow.</li>
22
20
<li>Replace both calls to <code>sprintf</code> with <code>snprintf</code>, specifying the define as the maximum length to copy. This will prevent the buffer overflow.</li>
23
21
<li>Consider using the %g format specifier instead of %f.</li>
that storage for strings has sufficient space for character data and
34
32
the null terminator</a>.</li>
35
33
<li>M. Howard, D. Leblanc, J. Viega, <i>19 Deadly Sins of Software Security: Programming Flaws and How to Fix Them</i>, McGraw-Hill Osborne, 2005.</li>
Copy file name to clipboardExpand all lines: cpp/ql/src/Security/CWE/CWE-676/PotentiallyDangerousFunction.qhelp
+8-4Lines changed: 8 additions & 4 deletions
Original file line number
Diff line number
Diff line change
@@ -5,9 +5,11 @@
5
5
<overview>
6
6
<p>This rule finds calls to functions that are dangerous to
7
7
use. Currently, it checks for calls
8
-
to <code>gmtime</code>. See <strong>Related rules</strong>
8
+
to <code>gets</code> and <code>gmtime</code>. See <strong>Related rules</strong>
9
9
below for rules that identify other dangerous functions.</p>
10
10
11
+
<p>The <code>gets</code> function is one of the vulnerabilities exploited by the Internet Worm of 1988, one of the first computer worms to spread through the Internet.</p>
12
+
11
13
<p>The <code>gmtime</code> function fills data into a <code>tm</code>
12
14
struct in shared memory and then returns a pointer to that struct. If
13
15
the function is called from multiple places in the same program, and
@@ -17,7 +19,9 @@ then the calls will overwrite each other's data.</p>
17
19
</overview>
18
20
<recommendation>
19
21
20
-
<p>It is safer to use <code>gmtime_r</code>.
22
+
<p>Replace calls to <code>gets</code> with <code>fgets</code>, specifying the maximum length to copy. This will prevent the buffer overflow.</p>
23
+
24
+
<p>Replace calls to <code>gmtime</code> with <code>gmtime_r</code>.
21
25
With <code>gmtime_r</code>, the application code manages allocation of
22
26
the <code>tm</code> struct. That way, separate calls to the function
23
27
can use their own storage.</p>
@@ -48,7 +52,7 @@ rules for the following CWEs:</p>
0 commit comments