summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlejandro Colomar <alx@kernel.org>2024-01-29 15:53:34 +0100
committerSerge Hallyn <serge@hallyn.com>2024-03-14 16:30:46 -0500
commitbed18501b1a198a4c5cb177a4cff8685e5a81abf (patch)
treee8cb320accf465006c09297e6abfc5bc02e89fb5
parent8fcf6cccff64cf270b8d4596dca3e6fd763f846c (diff)
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 <alx@kernel.org>
-rw-r--r--lib/time/day_to_str.h9
-rw-r--r--src/chage.c12
2 files changed, 10 insertions, 11 deletions
diff --git a/lib/time/day_to_str.h b/lib/time/day_to_str.h
index 6aa855ac..96cec6e1 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 88e06cd3..ca61cffd 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);
}