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: change-notes/1.20/analysis-cpp.md
+2Lines changed: 2 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -23,6 +23,8 @@
23
23
| Lossy function result cast (`cpp/lossy-function-result-cast`) | Fewer false positive results | The whitelist of rounding functions built into this query has been expanded. |
24
24
| Unused static variable (`cpp/unused-static-variable`) | Fewer false positive results | Variables with the attribute `unused` are now excluded from the query. |
25
25
| Resource not released in destructor (`cpp/resource-not-released-in-destructor`) | Fewer false positive results | Fix false positives where a resource is released via a virtual method call, function pointer, or lambda. |
26
+
| Use of inherently dangerous function (`cpp/potential-buffer-overflow`) | Cleaned up | This query no longer catches uses of `gets`, and has been renamed 'Potential buffer overflow'. |
27
+
| Use of potentially dangerous function (`cpp/potentially-dangerous-function`) | More correct results | This query now catches uses of `gets`. |
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.</p>
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
+9-4Lines changed: 9 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. The <code>gets</code> function provides no way to limit the amount of data that is read and stored, so without prior knowledge of the input it is impossible to use it safely with any size of buffer.</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,8 @@ rules for the following CWEs:</p>
<li>E. Spafford. <i>The Internet Worm Program: An Analysis</i>. Purdue Technical Report CSD-TR-823, <ahref="http://www.textfiles.com/100/tr823.txt">(online)</a>, 1988.</li>
57
+
<li>SEI CERT C Coding Standard: <ahref="https://wiki.sei.cmu.edu/confluence/display/c/CON33-C.+Avoid+race+conditions+when+using+library+functions">CON33-C. Avoid race conditions when using library functions</a>.</li>
0 commit comments