From: Alejandro Colomar Date: Mon, 29 Jan 2024 14:53:34 +0000 (+0100) Subject: lib/, src/: Call gmtime_r(3) instead of gmtime(3) X-Git-Tag: 4.15.1~22 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=bed18501b1a198a4c5cb177a4cff8685e5a81abf;p=thirdparty%2Fshadow.git lib/, src/: Call gmtime_r(3) instead of gmtime(3) 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 --- diff --git a/lib/time/day_to_str.h b/lib/time/day_to_str.h index 6aa855ac7..96cec6e1f 100644 --- a/lib/time/day_to_str.h +++ b/lib/time/day_to_str.h @@ -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); } diff --git a/src/chage.c b/src/chage.c index 88e06cd3f..ca61cffdc 100644 --- a/src/chage.c +++ b/src/chage.c @@ -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); }