From 5e6b5fbe8ab31f8027411644c07434d2d33a9f72 Mon Sep 17 00:00:00 2001 From: ejurgensen Date: Mon, 10 Aug 2020 22:19:34 +0200 Subject: [PATCH] [httpd/logger] Use gmtime_r/localtime_r instead of gmtime/localtime gmtime and localtime are not thread safe credit lgtm.com --- src/httpd.c | 3 ++- src/logger.c | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/httpd.c b/src/httpd.c index ffb03d87..29a347d5 100644 --- a/src/httpd.c +++ b/src/httpd.c @@ -325,11 +325,12 @@ httpd_request_not_modified_since(struct evhttp_request *req, time_t mtime) struct evkeyvalq *output_headers; char last_modified[1000]; const char *modified_since; + struct tm timebuf; input_headers = evhttp_request_get_input_headers(req); modified_since = evhttp_find_header(input_headers, "If-Modified-Since"); - strftime(last_modified, sizeof(last_modified), "%a, %d %b %Y %H:%M:%S %Z", gmtime(&mtime)); + strftime(last_modified, sizeof(last_modified), "%a, %d %b %Y %H:%M:%S %Z", gmtime_r(&mtime, &timebuf)); // Return not modified, if given timestamp matches "If-Modified-Since" request header if (modified_since && (strcasecmp(last_modified, modified_since) == 0)) diff --git a/src/logger.c b/src/logger.c index 1b36cfcb..6f017ff9 100644 --- a/src/logger.c +++ b/src/logger.c @@ -117,6 +117,7 @@ vlogger_writer(int severity, int domain, const char *fmt, va_list args) char content[2048]; char stamp[32]; time_t t; + struct tm timebuf; int ret; va_copy(ap, args); @@ -136,7 +137,7 @@ vlogger_writer(int severity, int domain, const char *fmt, va_list args) if (logfile) { t = time(NULL); - ret = strftime(stamp, sizeof(stamp), "%Y-%m-%d %H:%M:%S", localtime(&t)); + ret = strftime(stamp, sizeof(stamp), "%Y-%m-%d %H:%M:%S", localtime_r(&t, &timebuf)); if (ret == 0) stamp[0] = '\0';