From 8c2360fd560f48ce04cb03e0e5eaedfc6d1027ad Mon Sep 17 00:00:00 2001 From: Thulinma Date: Mon, 21 May 2018 09:54:05 +0200 Subject: [PATCH] Replaced all instances of localtime with localtime_r --- lib/util.cpp | 3 ++- src/controller/controller.cpp | 3 ++- src/controller/controller_api.cpp | 3 ++- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/lib/util.cpp b/lib/util.cpp index 4176459c..5141dda4 100644 --- a/lib/util.cpp +++ b/lib/util.cpp @@ -310,9 +310,10 @@ namespace Util{ } time_t rawtime; struct tm *timeinfo; + struct tm timetmp; char buffer[100]; time(&rawtime); - timeinfo = localtime(&rawtime); + timeinfo = localtime_r(&rawtime, &timetmp); strftime(buffer, 100, "%F %H:%M:%S", timeinfo); dprintf(out, "%s[%s] ", color_time, buffer); if (progname && progpid && strlen(progname) && strlen(progpid)){ diff --git a/src/controller/controller.cpp b/src/controller/controller.cpp index bcb2eac3..b63c2af9 100644 --- a/src/controller/controller.cpp +++ b/src/controller/controller.cpp @@ -180,9 +180,10 @@ int main_loop(int argc, char **argv){ dup2(output, STDERR_FILENO); time_t rawtime; struct tm *timeinfo; + struct tm tmptime; char buffer[25]; time(&rawtime); - timeinfo = localtime(&rawtime); + timeinfo = localtime_r(&rawtime, &tmptime); strftime(buffer, 25, "%c", timeinfo); std::cerr << std::endl << std::endl diff --git a/src/controller/controller_api.cpp b/src/controller/controller_api.cpp index 66c1ea03..0df51a57 100644 --- a/src/controller/controller_api.cpp +++ b/src/controller/controller_api.cpp @@ -15,7 +15,8 @@ /// Returns the challenge string for authentication, given the socket connection. std::string getChallenge(Socket::Connection & conn){ time_t Time = time(0); - tm * TimeInfo = localtime( &Time); + tm tmptime; + tm * TimeInfo = localtime_r( &Time, &tmptime); std::stringstream Date; Date << TimeInfo->tm_mday << "-" << TimeInfo->tm_mon << "-" << TimeInfo->tm_year + 1900; return Secure::md5(Date.str().c_str() + conn.getHost());