From 4c210a29bc57d584db4e69a28d27fee8d75956cc Mon Sep 17 00:00:00 2001 From: Alejandro Colomar Date: Mon, 13 Mar 2023 01:21:42 +0100 Subject: [PATCH] Fix su(1) silent truncation * src/su.c (check_perms): Do not silently truncate user name. Reported-by: Paul Eggert Co-developed-by: Paul Eggert Signed-off-by: Alejandro Colomar Reviewed-by: Iker Pedrosa --- src/su.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/su.c b/src/su.c index 9c134a9b..3402f9be 100644 --- a/src/su.c +++ b/src/su.c @@ -658,7 +658,13 @@ static /*@only@*/struct passwd * check_perms (void) SYSLOG ((LOG_INFO, "Change user from '%s' to '%s' as requested by PAM", name, tmp_name)); - strlcpy (name, tmp_name, sizeof(name)); + if (strlcpy (name, tmp_name, sizeof(name)) >= sizeof(name)) { + fprintf (stderr, _("Overlong user name '%s'\n"), + tmp_name); + SYSLOG ((LOG_NOTICE, "Overlong user name '%s'", + tmp_name)); + su_failure (caller_tty, true); + } pw = xgetpwnam (name); if (NULL == pw) { (void) fprintf (stderr,