Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit f7e7737

Browse files
committed
CPP: Update qhelp.
1 parent 87a25f0 commit f7e7737

2 files changed

Lines changed: 11 additions & 11 deletions

File tree

cpp/ql/src/Likely Bugs/Memory Management/PotentialBufferOverflow.qhelp

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,12 @@
33
"qhelp.dtd">
44
<qhelp>
55
<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.
98

109
</overview>
1110
<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>
1312

1413
</recommendation>
1514
<example>
@@ -18,7 +17,6 @@ is one of the vulnerabilities exploited by the Internet Worm of 1988, one of the
1817
<p>To improve the security of this example code, three changes should be made:</p>
1918
<ol>
2019
<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>
2220
<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>
2321
<li>Consider using the %g format specifier instead of %f.</li>
2422
</ol>
@@ -33,8 +31,6 @@ Standard: <a href="https://www.securecoding.cert.org/confluence/display/c/STR31-
3331
that storage for strings has sufficient space for character data and
3432
the null terminator</a>.</li>
3533
<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>
36-
<li>Wikipedia: <a href="http://en.wikipedia.org/wiki/Morris_worm">Morris worm</a>.</li>
37-
<li>E. Spafford. <i>The Internet Worm Program: An Analysis</i>. Purdue Technical Report CSD-TR-823, <a href="http://www.textfiles.com/100/tr823.txt">(online)</a>, 1988.</li>
3834

3935

4036
</references>

cpp/ql/src/Security/CWE/CWE-676/PotentiallyDangerousFunction.qhelp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,11 @@
55
<overview>
66
<p>This rule finds calls to functions that are dangerous to
77
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>
99
below for rules that identify other dangerous functions.</p>
1010

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+
1113
<p>The <code>gmtime</code> function fills data into a <code>tm</code>
1214
struct in shared memory and then returns a pointer to that struct. If
1315
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>
1719
</overview>
1820
<recommendation>
1921

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>.
2125
With <code>gmtime_r</code>, the application code manages allocation of
2226
the <code>tm</code> struct. That way, separate calls to the function
2327
can use their own storage.</p>
@@ -48,7 +52,7 @@ rules for the following CWEs:</p>
4852

4953
</section>
5054
<references>
51-
52-
55+
<li>Wikipedia: <a href="http://en.wikipedia.org/wiki/Morris_worm">Morris worm</a>.</li>
56+
<li>E. Spafford. <i>The Internet Worm Program: An Analysis</i>. Purdue Technical Report CSD-TR-823, <a href="http://www.textfiles.com/100/tr823.txt">(online)</a>, 1988.</li>
5357
</references>
5458
</qhelp>

0 commit comments

Comments
 (0)