CodeQL queries 1.23
This rule finds calls to functions that are dangerous to
use. Currently, it checks for calls
The time related functions such as
fill data into a
tm struct or
char array in
shared memory and then returns a pointer to that memory. If
the function is called from multiple places in the same program, and
especially if it is called from multiple threads in the same program,
then the calls will overwrite each other's data.
Replace calls to
gmtime_r, the application code manages allocation of
tm struct. That way, separate calls to the function
can use their own storage.
Similarly replace calls to
localtime_r, calls to
ctime_r and calls to
The following example checks the local time in two ways:
The first version uses
gmtime, so it is vulnerable to
its data being overwritten by another thread. Even if this code is not
used in a multi-threaded context right now, future changes may
make the program multi-threaded. The second version of the code
gmtime_r. Since it allocates a new
struct on every call, it is immune to other calls to
- SEI CERT C Coding Standard: CON33-C. Avoid race conditions when using library functions.
- Common Weakness Enumeration: CWE-676.