Fixed unsafe use of localtime

Since localtime is not thread-safe it should not be used in multithreaded
contexts. For this reason all calls to localtime were changed to localtime_r
in code where concurrency issues were possible.

Internal tests were left unchanged because they aren't multithreaded.
This commit is contained in:
Johan Wikman
2015-11-19 15:36:40 +02:00
committed by Markus Makela
parent 84d2c72db2
commit 6164b7f301
9 changed files with 43 additions and 51 deletions

View File

@ -491,7 +491,9 @@ static void httpd_send_headers(DCB *dcb, int final)
const char *fmt = "%a, %d %b %Y %H:%M:%S GMT";
time_t httpd_current_time = time(NULL);
strftime(date, sizeof(date), fmt, localtime(&httpd_current_time));
struct tm tm;
localtime_r(&httpd_current_time, &tm);
strftime(date, sizeof(date), fmt, &tm);
dcb_printf(dcb, "HTTP/1.1 200 OK\r\nDate: %s\r\nServer: %s\r\nConnection: close\r\nContent-Type: application/json\r\n", date, HTTP_SERVER_STRING);