anitazha / rpms / systemd

Forked from rpms/systemd 3 years ago
Clone

Blame SOURCES/0773-timedate-use-gmtime_r-and-localtime_r.patch

661545
From 52df8972d4005b23f7c2e52b0cf7210b8c594876 Mon Sep 17 00:00:00 2001
661545
From: Lennart Poettering <lennart@poettering.net>
661545
Date: Mon, 25 Jun 2018 14:29:25 +0200
661545
Subject: [PATCH] timedate: use gmtime_r() and localtime_r()
661545
661545
gmtime() and localtime() operate on a static buffer. let's avoid this,
661545
as we never know whether some library might use these calls in some
661545
backrgound thread.
661545
661545
Discovered by lgtm:
661545
661545
https://lgtm.com/projects/g/systemd/systemd/
661545
(cherry picked from commit e46acb7950a9f07ac60d772309de842c444ad2bd)
661545
661545
Resolves: #1694605
661545
---
661545
 src/timedate/timedated.c | 20 ++++++++++----------
661545
 1 file changed, 10 insertions(+), 10 deletions(-)
661545
661545
diff --git a/src/timedate/timedated.c b/src/timedate/timedated.c
661545
index 09d0dbabcd..afd54a8936 100644
661545
--- a/src/timedate/timedated.c
661545
+++ b/src/timedate/timedated.c
661545
@@ -542,9 +542,9 @@ static int method_set_local_rtc(sd_bus *bus, sd_bus_message *m, void *userdata,
661545
                  * initialize the timezone fields of
661545
                  * struct tm. */
661545
                 if (c->local_rtc)
661545
-                        tm = *localtime(&ts.tv_sec);
661545
+                        localtime_r(&ts.tv_sec, &tm;;
661545
                 else
661545
-                        tm = *gmtime(&ts.tv_sec);
661545
+                        gmtime_r(&ts.tv_sec, &tm;;
661545
 
661545
                 /* Override the main fields of
661545
                  * struct tm, but not the timezone
661545
@@ -562,15 +562,15 @@ static int method_set_local_rtc(sd_bus *bus, sd_bus_message *m, void *userdata,
661545
                 }
661545
 
661545
         } else {
661545
-                struct tm *tm;
661545
+                struct tm tm;
661545
 
661545
                 /* Sync RTC from system clock */
661545
                 if (c->local_rtc)
661545
-                        tm = localtime(&ts.tv_sec);
661545
+                        localtime_r(&ts.tv_sec, &tm;;
661545
                 else
661545
-                        tm = gmtime(&ts.tv_sec);
661545
+                        gmtime_r(&ts.tv_sec, &tm;;
661545
 
661545
-                clock_set_hwclock(tm);
661545
+                clock_set_hwclock(&tm;;
661545
         }
661545
 
661545
         log_info("RTC configured to %s time.", c->local_rtc ? "local" : "UTC");
661545
@@ -585,7 +585,7 @@ static int method_set_time(sd_bus *bus, sd_bus_message *m, void *userdata, sd_bu
661545
         Context *c = userdata;
661545
         int64_t utc;
661545
         struct timespec ts;
661545
-        struct tm* tm;
661545
+        struct tm tm;
661545
         int r;
661545
 
661545
         assert(bus);
661545
@@ -633,10 +633,10 @@ static int method_set_time(sd_bus *bus, sd_bus_message *m, void *userdata, sd_bu
661545
 
661545
         /* Sync down to RTC */
661545
         if (c->local_rtc)
661545
-                tm = localtime(&ts.tv_sec);
661545
+                localtime_r(&ts.tv_sec, &tm;;
661545
         else
661545
-                tm = gmtime(&ts.tv_sec);
661545
-        clock_set_hwclock(tm);
661545
+                gmtime_r(&ts.tv_sec, &tm;;
661545
+        clock_set_hwclock(&tm;;
661545
 
661545
         log_struct(LOG_INFO,
661545
                    LOG_MESSAGE_ID(SD_MESSAGE_TIME_CHANGE),