sipdump: use localtime_r() for a safer multi-thread usage
authorVictor Seva <linuxmaniac@torreviejawireless.org>
Tue, 12 May 2020 14:08:21 +0000 (16:08 +0200)
committerVictor Seva <linuxmaniac@torreviejawireless.org>
Tue, 12 May 2020 14:08:21 +0000 (16:08 +0200)
src/modules/sipdump/sipdump_mod.c

index e61fea0..a986846 100644 (file)
@@ -204,10 +204,11 @@ typedef struct sipdump_info {
 int sipdump_buffer_write(sipdump_info_t *sdi, str *obuf)
 {
        struct timeval tv;
-       struct tm *ti;
+       struct tm ti;
+       char t_buf[26] = {0};
 
        gettimeofday(&tv, NULL);
-       ti = localtime(&tv.tv_sec);
+       localtime_r(&tv.tv_sec, &ti);
        obuf->len = snprintf(_sipdump_wbuf, SIPDUMP_WBUF_SIZE,
                "====================\n"
                "tag: %.*s\n"
@@ -227,7 +228,7 @@ int sipdump_buffer_write(sipdump_info_t *sdi, str *obuf)
                my_pid(),
                process_no,
                (unsigned long)tv.tv_sec, (unsigned long)tv.tv_usec,
-               asctime(ti),
+               asctime_r(&ti, t_buf),
                sdi->proto.len, sdi->proto.s, sdi->af.len, sdi->af.s,
                sdi->src_ip.len, sdi->src_ip.s, sdi->src_port,
                sdi->dst_ip.len, sdi->dst_ip.s, sdi->dst_port,