]> git.ipfire.org Git - thirdparty/shadow.git/commitdiff
src/passwd.c: Switch to day precision
authorTobias Stoeckmann <tobias@stoeckmann.org>
Thu, 14 Dec 2023 10:54:00 +0000 (11:54 +0100)
committerSerge Hallyn <serge@hallyn.com>
Fri, 5 Jan 2024 21:41:12 +0000 (15:41 -0600)
The size of time_t varies across systems, but since data type long is
more than enough to calculate with days (precision of shadow file),
use it instead.

Just in case a shadow file contains huge values, check for a possible
signed integer overflow.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
Link: <https://github.com/shadow-maint/shadow/pull/876>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
src/passwd.c

index ef7bee85fff608a02a0136da9a51c5efa07dcbec..a24e62dfd020b794de0bec9fa7203c75890ae513 100644 (file)
@@ -343,7 +343,6 @@ static int new_password (const struct passwd *pw)
  */
 static void check_password (const struct passwd *pw, const struct spwd *sp)
 {
-       time_t now;
        int exp_status;
 
        exp_status = isexpired (pw, sp);
@@ -363,8 +362,6 @@ static void check_password (const struct passwd *pw, const struct spwd *sp)
                return;
        }
 
-       (void) time (&now);
-
        /*
         * Expired accounts cannot be changed ever. Passwords which are
         * locked may not be changed. Passwords where min > max may not be
@@ -387,10 +384,11 @@ static void check_password (const struct passwd *pw, const struct spwd *sp)
         * Passwords may only be changed after sp_min time is up.
         */
        if (sp->sp_lstchg > 0) {
-               time_t ok;
-               ok = (time_t) sp->sp_lstchg * DAY;
+               long now, ok;
+               now = time(NULL) / DAY;
+               ok = sp->sp_lstchg;
                if (sp->sp_min > 0) {
-                       ok += (time_t) sp->sp_min * DAY;
+                       ok += sp->sp_min;
                }
 
                if (now < ok) {