From 8c3f6d2b19ed1811007bdb58c4742eb6bf2b2741 Mon Sep 17 00:00:00 2001 From: akallabeth Date: Mon, 25 May 2020 13:56:24 +0200 Subject: [PATCH] Replaced localtime with localtime_r (cherry picked from commit 240fdd07b123594a1f7a460de7e6877b1963d09e) --- channels/printer/client/cups/printer_cups.c | 3 ++- channels/printer/client/win/printer_win.c | 3 ++- winpr/libwinpr/sysinfo/sysinfo.c | 3 ++- winpr/libwinpr/timezone/timezone.c | 7 ++++++- 4 files changed, 12 insertions(+), 4 deletions(-) diff --git a/channels/printer/client/cups/printer_cups.c b/channels/printer/client/cups/printer_cups.c index 1f9f07b24..56cbacecf 100644 --- a/channels/printer/client/cups/printer_cups.c +++ b/channels/printer/client/cups/printer_cups.c @@ -69,10 +69,11 @@ struct rdp_cups_print_job static void printer_cups_get_printjob_name(char* buf, size_t size, size_t id) { time_t tt; + struct tm tres; struct tm* t; tt = time(NULL); - t = localtime(&tt); + t = localtime_r(&tt, &tres); sprintf_s(buf, size - 1, "FreeRDP Print %04d-%02d-%02d %02d-%02d-%02d - Job %" PRIdz, t->tm_year + 1900, t->tm_mon + 1, t->tm_mday, t->tm_hour, t->tm_min, t->tm_sec, id); } diff --git a/channels/printer/client/win/printer_win.c b/channels/printer/client/win/printer_win.c index 5306f59fb..83dadba9f 100644 --- a/channels/printer/client/win/printer_win.c +++ b/channels/printer/client/win/printer_win.c @@ -78,13 +78,14 @@ struct rdp_win_print_job static WCHAR* printer_win_get_printjob_name(size_t id) { time_t tt; + struct tm tres; struct tm* t; WCHAR* str; size_t len = 1024; int rc; tt = time(NULL); - t = localtime(&tt); + t = localtime_r(&tt, &tres); str = calloc(len, sizeof(WCHAR)); if (!str) diff --git a/winpr/libwinpr/sysinfo/sysinfo.c b/winpr/libwinpr/sysinfo/sysinfo.c index 10884f7d1..139d6546e 100644 --- a/winpr/libwinpr/sysinfo/sysinfo.c +++ b/winpr/libwinpr/sysinfo/sysinfo.c @@ -242,11 +242,12 @@ BOOL SetSystemTime(CONST SYSTEMTIME* lpSystemTime) VOID GetLocalTime(LPSYSTEMTIME lpSystemTime) { time_t ct = 0; + struct tm tres; struct tm* ltm = NULL; WORD wMilliseconds = 0; ct = time(NULL); wMilliseconds = (WORD)(GetTickCount() % 1000); - ltm = localtime(&ct); + ltm = localtime_r(&ct, &tres); ZeroMemory(lpSystemTime, sizeof(SYSTEMTIME)); if (ltm) diff --git a/winpr/libwinpr/timezone/timezone.c b/winpr/libwinpr/timezone/timezone.c index 5475cb67a..507763897 100644 --- a/winpr/libwinpr/timezone/timezone.c +++ b/winpr/libwinpr/timezone/timezone.c @@ -339,12 +339,17 @@ winpr_get_current_time_zone_rule(const TIME_ZONE_RULE_ENTRY* rules, UINT32 count DWORD GetTimeZoneInformation(LPTIME_ZONE_INFORMATION lpTimeZoneInformation) { time_t t; + struct tm tres; + ; struct tm* local_time; TIME_ZONE_ENTRY* dtz; LPTIME_ZONE_INFORMATION tz = lpTimeZoneInformation; lpTimeZoneInformation->StandardBias = 0; time(&t); - local_time = localtime(&t); + local_time = localtime_r(&t, &tres); + if (!local_time) + goto out_error; + memset(tz, 0, sizeof(TIME_ZONE_INFORMATION)); #ifdef HAVE_TM_GMTOFF {