]> git.ipfire.org Git - thirdparty/shadow.git/commitdiff
Revert 3 cherry-picks
authorAlejandro Colomar <alx@kernel.org>
Tue, 20 Feb 2024 21:47:41 +0000 (22:47 +0100)
committerAlejandro Colomar <alx@kernel.org>
Tue, 20 Feb 2024 21:48:02 +0000 (22:48 +0100)
This changes pull some more dependencies.  That's too much for a stable
branch, I think.  If anyone needs them, please ask for them, but for now
let's keep them out.

Reverts: 9d5591fba90f ("src/passwd.c: check password length upper limit")
Reverts: dbdda2a48a77 ("lib/: Saturate addition to avoid overflow")
Reverts: 541d4dde23e8 ("src/chage.c: Unify long overflow checks in print_day_as_date()")
Signed-off-by: Alejandro Colomar <alx@kernel.org>
lib/age.c
lib/isexpired.c
src/chage.c
src/passwd.c

index 72a13eab51bcc6023ef5dcc96bb7e1808424043e..d9ef88c4c8a026f88611812ec4ab0f2aaf657513 100644 (file)
--- a/lib/age.c
+++ b/lib/age.c
 #include <stdio.h>
 #include <time.h>
 #include <errno.h>
-#include <pwd.h>
-#include <grp.h>
-
-#include "adds.h"
+#include "prototypes.h"
 #include "defines.h"
 #include "exitcodes.h"
-#include "prototypes.h"
-
+#include <pwd.h>
+#include <grp.h>
 
 #ident "$Id$"
 
@@ -165,8 +162,7 @@ void agecheck (/*@null@*/const struct spwd *sp)
                return;
        }
 
-       remain = addsl(sp->sp_lstchg, sp->sp_max, -now);
-
+       remain = sp->sp_lstchg + sp->sp_max - now;
        if (remain <= sp->sp_warn) {
                if (remain > 1) {
                        (void) printf (_("Your password will expire in %ld days.\n"),
index c275691f7267065cc9536c1a39ded38193cd8b2b..45c7601ec4bef15ef750d454bba281bd2b78b430 100644 (file)
 #include <config.h>
 
 #include <sys/types.h>
+#include "prototypes.h"
+#include "defines.h"
 #include <pwd.h>
 #include <time.h>
 
-#include "adds.h"
-#include "defines.h"
-#include "prototypes.h"
-
 #ident "$Id$"
 
 
@@ -40,7 +38,7 @@
  */
 int isexpired (const struct passwd *pw, /*@null@*/const struct spwd *sp)
 {
-       long  now;
+       long now;
 
        now = time(NULL) / DAY;
 
@@ -74,8 +72,7 @@ int isexpired (const struct passwd *pw, /*@null@*/const struct spwd *sp)
        if (   (sp->sp_lstchg > 0)
            && (sp->sp_max >= 0)
            && (sp->sp_inact >= 0)
-           && (now >= addsl(sp->sp_lstchg, sp->sp_max, sp->sp_inact)))
-       {
+           && (now >= (sp->sp_lstchg + sp->sp_max + sp->sp_inact))) {
                return 2;
        }
 
@@ -97,9 +94,9 @@ int isexpired (const struct passwd *pw, /*@null@*/const struct spwd *sp)
         * the password has expired.
         */
 
-       if (now >= addsl(sp->sp_lstchg, sp->sp_max))
+       if (now >= (sp->sp_lstchg + sp->sp_max)) {
                return 1;
-
+       }
        return 0;
 }
 
index ecbf8738a2e15674e1422f051eeb7555ad888160..8a6d3584a8c8771e28043b87cf7a8c5c4e4b9657 100644 (file)
@@ -72,7 +72,7 @@ static long expdate;
 /* local function prototypes */
 NORETURN static void usage (int status);
 static int new_fields (void);
-static void print_day_as_date (long day);
+static void print_date (time_t date);
 static void list_fields (void);
 static void process_flags (int argc, char **argv);
 static void check_flags (int argc, int opt_index);
@@ -227,22 +227,10 @@ static int new_fields (void)
        return 1;
 }
 
-
-static void
-print_day_as_date(long day)
+static void print_date (time_t date)
 {
-       char       buf[80];
-       time_t     date;
-       struct tm  *tp;
-
-       if (day < 0) {
-               puts(_("never"));
-               return;
-       }
-       if (__builtin_mul_overflow(day, DAY, &date)) {
-               puts(_("future"));
-               return;
-       }
+       struct tm *tp;
+       char buf[80];
 
        tp = gmtime (&date);
        if (NULL == tp) {
@@ -253,7 +241,6 @@ print_day_as_date(long day)
        }
 }
 
-
 /*
  * list_fields - display the current values of the expiration fields
  *
@@ -263,15 +250,21 @@ print_day_as_date(long day)
  */
 static void list_fields (void)
 {
+       long changed = 0;
+       long expires;
+
        /*
         * The "last change" date is either "never" or the date the password
         * was last modified. The date is the number of days since 1/1/1970.
         */
        (void) fputs (_("Last password change\t\t\t\t\t: "), stdout);
-       if (lstchgdate == 0) {
+       if (lstchgdate < 0 || lstchgdate > LONG_MAX / DAY) {
+               (void) puts (_("never"));
+       } else if (lstchgdate == 0) {
                (void) puts (_("password must be changed"));
        } else {
-               print_day_as_date(lstchgdate);
+               changed = lstchgdate * DAY;
+               print_date (changed);
        }
 
        /*
@@ -284,11 +277,11 @@ static void list_fields (void)
        } else if (   (lstchgdate < 0)
                   || (maxdays >= 10000)
                   || (maxdays < 0)
-                  || (LONG_MAX - lstchgdate < maxdays))
-       {
+                  || ((LONG_MAX - changed) / DAY < maxdays)) {
                (void) puts (_("never"));
        } else {
-               print_day_as_date(lstchgdate + maxdays);
+               expires = changed + maxdays * DAY;
+               print_date (expires);
        }
 
        /*
@@ -304,12 +297,12 @@ static void list_fields (void)
                   || (inactdays < 0)
                   || (maxdays >= 10000)
                   || (maxdays < 0)
-                  || (LONG_MAX - inactdays < maxdays)
-                  || (LONG_MAX - lstchgdate < maxdays + inactdays))
-       {
+                  || (maxdays > LONG_MAX - inactdays)
+                  || ((LONG_MAX - changed) / DAY < maxdays + inactdays)) {
                (void) puts (_("never"));
        } else {
-               print_day_as_date(lstchgdate + maxdays + inactdays);
+               expires = changed + (maxdays + inactdays) * DAY;
+               print_date (expires);
        }
 
        /*
@@ -317,7 +310,12 @@ static void list_fields (void)
         * password expiring or not.
         */
        (void) fputs (_("Account expires\t\t\t\t\t\t: "), stdout);
-       print_day_as_date(expdate);
+       if (expdate < 0 || LONG_MAX / DAY < expdate) {
+               (void) puts (_("never"));
+       } else {
+               expires = expdate * DAY;
+               print_date (expires);
+       }
 
        /*
         * Start with the easy numbers - the number of days before the
index ee25373b91451f6ae5ef9e937a053dbd7133cc7a..4549d95d7d8fc909b0ca1eed9e30d9937f1e7438 100644 (file)
@@ -195,7 +195,6 @@ static int new_password (const struct passwd *pw)
        char orig[PASS_MAX + 1];        /* Original password */
        char pass[PASS_MAX + 1];        /* New password */
        int i;                  /* Counter for retries */
-       int ret;
        bool warned;
        int pass_max_len = -1;
        const char *method;
@@ -301,14 +300,8 @@ static int new_password (const struct passwd *pw)
                if (warned && (strcmp (pass, cp) != 0)) {
                        warned = false;
                }
-               ret = STRTCPY (pass, cp);
+               STRFCPY (pass, cp);
                erase_pass (cp);
-               if (ret == -1) {
-                       (void) fputs (_("Password is too long.\n"), stderr);
-                       memzero (orig, sizeof orig);
-                       memzero (pass, sizeof pass);
-                       return -1;
-               }
 
                if (!amroot && (!obscure (orig, pass, pw) || reuse (pass, pw))) {
                        (void) puts (_("Try again."));