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/Security/CWE/CWE-676/PotentiallyDangerousFunction.qhelp
+11-4Lines changed: 11 additions & 4 deletions
Original file line number
Diff line number
Diff line change
@@ -5,13 +5,15 @@
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>gets</code> and <code>gmtime</code>. See <strong>Related rules</strong>
9
-
below for rules that identify other dangerous functions.</p>
8
+
to <code>gets</code>, <code>gmtime</code>, <code>localtime</code>,
9
+
<code>ctime</code> and <code>asctime</code>. See <strong>Related
10
+
rules</strong> below for rules that identify other dangerous functions.</p>
10
11
11
12
<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
13
13
-
<p>The <code>gmtime</code> function fills data into a <code>tm</code>
14
-
struct in shared memory and then returns a pointer to that struct. If
14
+
<p>The time related functions such as <code>gmtime</code>
15
+
fill data into a <code>tm</code> struct or <code>char</code> array in
16
+
shared memory and then returns a pointer to that memory. If
15
17
the function is called from multiple places in the same program, and
16
18
especially if it is called from multiple threads in the same program,
17
19
then the calls will overwrite each other's data.</p>
@@ -26,6 +28,11 @@ With <code>gmtime_r</code>, the application code manages allocation of
26
28
the <code>tm</code> struct. That way, separate calls to the function
27
29
can use their own storage.</p>
28
30
31
+
<p>Similarly replace calls to <code>localtime</code> with
32
+
<code>localtime_r</code>, calls to <code>ctime</code> with
33
+
<code>ctime_r</code> and calls to <code>asctime</code> with
34
+
<code>asctime_r</code>.</p>
35
+
29
36
</recommendation>
30
37
<example>
31
38
<p>The following example checks the local time in two ways:</p>
0 commit comments