From: Tomas Halman Date: Fri, 16 Feb 2024 08:52:39 +0000 (+0100) Subject: src/passwd.c: check password length upper limit X-Git-Tag: 4.14.6~10 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=9d5591fba90f;p=thirdparty%2Fshadow.git src/passwd.c: check password length upper limit The passwd silently truncated the password length to PASS_MAX. This patch introduces check that prints an error message and exits the call. Signed-off-by: Tomas Halman Reviewed-by: Alejandro Colomar Cherry-picked-from: f024002b3d66 ("src/passwd.c: inconsistent password length limit") Cc: Serge Hallyn Link: Signed-off-by: Alejandro Colomar --- diff --git a/src/passwd.c b/src/passwd.c index 4549d95d7..ee25373b9 100644 --- a/src/passwd.c +++ b/src/passwd.c @@ -195,6 +195,7 @@ 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; @@ -300,8 +301,14 @@ static int new_password (const struct passwd *pw) if (warned && (strcmp (pass, cp) != 0)) { warned = false; } - STRFCPY (pass, cp); + ret = STRTCPY (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."));