Skip to content

Commit a2d96c6

Browse files
committed
CWE-676 - localtime
Signed-off-by: Krayon <[email protected]>
1 parent 2b692da commit a2d96c6

File tree

1 file changed

+3
-6
lines changed

1 file changed

+3
-6
lines changed

log.c

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
#define max_src_len "16"
3333

3434
FILE *_logfile = NULL;
35+
struct tm _timey;
3536

3637
/*
3738
LOG LINE FORMAT:
@@ -61,16 +62,12 @@ void std_output(FILE *strm, const char *srcfile, const int line
6162
char *nl; // new line ptr
6263
va_list ap;
6364
time_t t;
64-
struct tm *tmp;
6565

6666
if (!strm) return;
6767

6868
t = time(NULL);
69-
tmp = localtime(&t);
70-
if (
71-
tmp == NULL
72-
|| strftime(_logtime, sizeof(_logtime), "%0Y%0m%0dT%0H%0M%0S%z", tmp) == 0
73-
) {
69+
localtime_r(&t, &_timey);
70+
if (strftime(_logtime, sizeof(_logtime), "%0Y%0m%0dT%0H%0M%0S%z", &_timey) == 0) {
7471
// "20140815T231613+1000"
7572
snprintf(_logtime, 32, "===== UNKNOWN =====");
7673
}

0 commit comments

Comments
 (0)