]> git.ipfire.org Git - thirdparty/shadow.git/commitdiff
lib/, src/: Call gmtime_r(3) instead of gmtime(3)
authorAlejandro Colomar <alx@kernel.org>
Mon, 29 Jan 2024 14:53:34 +0000 (15:53 +0100)
committerSerge Hallyn <serge@hallyn.com>
Thu, 14 Mar 2024 21:30:46 +0000 (16:30 -0500)
It's trivial to do the change, and it removes a CodeQL warning.
We don't need to be reentrant, but it doesn't hurt either.

Signed-off-by: Alejandro Colomar <alx@kernel.org>
lib/time/day_to_str.h
src/chage.c

index 6aa855ac70feb43045956ac54dee30f1ef106f51..96cec6e1fe878a6824330db2d84fd4a82e0535a8 100644 (file)
@@ -25,8 +25,8 @@ inline void day_to_str(size_t size, char buf[size], long day);
 inline void
 day_to_str(size_t size, char buf[size], long day)
 {
-       time_t           date;
-       const struct tm  *tm;
+       time_t     date;
+       struct tm  tm;
 
        if (day < 0) {
                strtcpy(buf, "never", size);
@@ -38,13 +38,12 @@ day_to_str(size_t size, char buf[size], long day)
                return;
        }
 
-       tm = gmtime(&date);
-       if (tm == NULL) {
+       if (gmtime_r(&date, &tm) == NULL) {
                strtcpy(buf, "future", size);
                return;
        }
 
-       if (strftime(buf, size, "%Y-%m-%d", tm) == 0)
+       if (strftime(buf, size, "%Y-%m-%d", &tm) == 0)
                strtcpy(buf, "future", size);
 }
 
index 88e06cd3fe7633befdf26ce42bc56631376ed5d9..ca61cffdc6efa2dc3c4f11ae61692e9825d4700d 100644 (file)
@@ -237,7 +237,7 @@ print_day_as_date(long day)
 {
        char       buf[80];
        time_t     date;
-       struct tm  *tp;
+       struct tm  tm;
 
        if (day < 0) {
                puts(_("never"));
@@ -248,13 +248,13 @@ print_day_as_date(long day)
                return;
        }
 
-       tp = gmtime (&date);
-       if (NULL == tp) {
+       if (gmtime_r(&date, &tm) == NULL) {
                (void) printf ("time_t: %lu\n", (unsigned long)date);
-       } else {
-               (void) strftime (buf, sizeof buf, iflg ? "%Y-%m-%d" : "%b %d, %Y", tp);
-               (void) puts (buf);
+               return;
        }
+
+       (void) strftime (buf, sizeof buf, iflg ? "%Y-%m-%d" : "%b %d, %Y", &tm);
+       (void) puts (buf);
 }