]> git.ipfire.org Git - thirdparty/shadow.git/commitdiff
src/passwd.c: inconsistent password length limit
authorTomas Halman <tomas@halman.net>
Fri, 16 Feb 2024 08:33:02 +0000 (09:33 +0100)
committerAlejandro Colomar <alx@kernel.org>
Fri, 16 Feb 2024 22:34:56 +0000 (23:34 +0100)
The passwd utility had hardcoded limit for password lenght set
to 200 characters. In the agetpass.c is used PASS_MAX for
this purpose.

This patch moves the PASS_MAX definition to common place
and uses it in both places.

Signed-off-by: Tomas Halman <tomas@halman.net>
Reviewed-by: Alejandro Colomar <alx@kernel.org>
Cherry-picked-from: f024002b3d66 ("src/passwd.c: inconsistent password length limit")
Cc: Serge Hallyn <serge@hallyn.com>
Link: <https://github.com/shadow-maint/shadow/pull/953>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
lib/agetpass.c
lib/defines.h
src/passwd.c

index 576b766e5ad989efeb263fe3ae69813b0bb1ced9..15146c86199cfc0ce5856f444caa87c0d5250e74 100644 (file)
@@ -9,7 +9,6 @@
 
 #include <limits.h>
 #include <readpassphrase.h>
-#include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
 
 #endif /* WITH_LIBBSD */
 
 
-#if !defined(PASS_MAX)
-#define PASS_MAX  BUFSIZ - 1
-#endif
-
-
 /*
  * SYNOPSIS
  *     [[gnu::malloc(erase_pass)]]
index bd32f00b43a0e13909b9532ccfec0d50c7a4a45e..df28411eb346ebfe984c448490684ebfa0f19d1b 100644 (file)
@@ -25,6 +25,7 @@
     ((N) == 1 ? (const char *) (Msgid1) : (const char *) (Msgid2))
 #endif
 
+#include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
 
@@ -240,4 +241,14 @@ static inline void memzero(void *ptr, size_t size)
 #  define shadow_getenv(name) getenv(name)
 #endif
 
+/*
+ * Maximum password length
+ *
+ * Consider that there is also limit in PAM (PAM_MAX_RESP_SIZE)
+ * currently set to 512.
+ */
+#if !defined(PASS_MAX)
+#define PASS_MAX  BUFSIZ - 1
+#endif
+
 #endif                         /* _DEFINES_H_ */
index 3e0d8fde4dade53db13c40ba1e465fde8cc36675..4549d95d7d8fc909b0ca1eed9e30d9937f1e7438 100644 (file)
@@ -192,8 +192,8 @@ static int new_password (const struct passwd *pw)
        char *cipher;           /* Pointer to cipher text */
        const char *salt;       /* Pointer to new salt */
        char *cp;               /* Pointer to agetpass() response */
-       char orig[200];         /* Original password */
-       char pass[200];         /* New password */
+       char orig[PASS_MAX + 1];        /* Original password */
+       char pass[PASS_MAX + 1];        /* New password */
        int i;                  /* Counter for retries */
        bool warned;
        int pass_max_len = -1;