]> git.ipfire.org Git - thirdparty/shadow.git/commitdiff
lib/strtoday.c: strtoday(): Fix calculation
authorAlejandro Colomar <alx@kernel.org>
Thu, 8 Feb 2024 11:53:24 +0000 (12:53 +0100)
committerSerge Hallyn <serge@hallyn.com>
Tue, 13 Feb 2024 22:05:12 +0000 (16:05 -0600)
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: <https://github.com/shadow-maint/shadow/issues/939>
Reported-by: Michael Vetter <jubalh@iodoru.org>
Tested-by: Gus Kenion <https://github.com/kenion>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
lib/strtoday.c

index ad1ed61f4309f8c6a8f3fcb3831c3fadbff7eb3e..0c7a0b012bed472ae25ebc1d7b40980a03873b8b 100644 (file)
@@ -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;
 }