From 7d97fd9a1cae778c3eacf16e09f5da3689d616c6 Mon Sep 17 00:00:00 2001 From: Damien Miller Date: Sun, 29 Dec 2013 17:40:18 +1100 Subject: - (djm) [loginrec.c] Check for username truncation when looking up lastlog entries --- loginrec.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'loginrec.c') diff --git a/loginrec.c b/loginrec.c index 59e8a44e..8844db54 100644 --- a/loginrec.c +++ b/loginrec.c @@ -310,9 +310,12 @@ login_get_lastlog(struct logininfo *li, const uid_t uid) fatal("%s: Cannot find account for uid %ld", __func__, (long)uid); - /* No MIN_SIZEOF here - we absolutely *must not* truncate the - * username (XXX - so check for trunc!) */ - strlcpy(li->username, pw->pw_name, sizeof(li->username)); + if (strlcpy(li->username, pw->pw_name, sizeof(li->username)) >= + sizeof(li->username)) { + error("%s: username too long (%lu > max %lu)", __func__, + strlen(pw->pw_name), sizeof(li->username) - 1); + return NULL; + } if (getlast_entry(li)) return (li); @@ -320,7 +323,6 @@ login_get_lastlog(struct logininfo *li, const uid_t uid) return (NULL); } - /* * login_alloc_entry(int, char*, char*, char*) - Allocate and initialise * a logininfo structure -- cgit v1.2.3