From: Alejandro Colomar Date: Thu, 8 Feb 2024 11:53:24 +0000 (+0100) Subject: lib/strtoday.c: strtoday(): Fix calculation X-Git-Tag: 4.14.6~12 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=c4eae35466f1e0d5594e94ad6fdb6c50695b385f;p=thirdparty%2Fshadow.git lib/strtoday.c: strtoday(): Fix calculation Days officially roll over at 00:00 UTC, not at 12:00 UTC. I see no reason to add that half day. Also, remove the comment. It's likely to get stale. So, get_date() gets the number of seconds since the Epoch. I wonder how that thing works, but I'll assume it's something similar to getdate(3) + mktime(3). After that, we need to convert seconds since Epoch to days since Epoch. That should be a simple division, AFAICS, since Epoch is "1970‐01‐01 00:00:00 +0000 (UTC)". See mktime(3). Fixes: 45c6603cc86c ("[svn-upgrade] Integrating new upstream version, shadow (19990709)") Link: Reported-by: Michael Vetter Tested-by: Gus Kenion Signed-off-by: Alejandro Colomar Cherry-picked-from: 1175932c0c86 ("lib/strtoday.c: strtoday(): Fix calculation") Cc: "Serge E. Hallyn" Link: Signed-off-by: Alejandro Colomar --- diff --git a/lib/strtoday.c b/lib/strtoday.c index d4c22af23..30eb7b460 100644 --- a/lib/strtoday.c +++ b/lib/strtoday.c @@ -68,10 +68,9 @@ long strtoday (const char *str) return retdate; } - t = get_date (str, NULL); + t = get_date(str, NULL); if ((time_t) - 1 == t) { return -2; } - /* convert seconds to days since 1970-01-01 */ - return (t + DAY / 2) / DAY; + return t / DAY; }