Skip to contentSkip to conversation

login: prevent OOB read on illegal /etc/hushlogins

PATCH Applied Tobias Stoeckmann 2 participants 2 messages Mar 12, 2017 – Mar 13, 2017 Util-Linux package

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 login: prevent OOB read on illegal /etc/hushlogins

If the file /etc/hushlogins exists and a line starts with '\0', the login tools are prone to an off-by-one read.

I see no reliability issue with this, as it would clearly need a hostile action from a system administrator. But for the sake of correctness, I've sent this patch nonetheless.

---
 login-utils/logindefs.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
login-utils/logindefs.c +2 -1
index f02c4752d..213ff8d25 100644
@@ -344,7 +344,8 @@ int get_hushlogin_status(struct passwd *pwd, int force_check)
 				continue;	/* ignore errors... */
 
 			while (ok == 0 && fgets(buf, sizeof(buf), f)) {
-				buf[strlen(buf) - 1] = '\0';
+				if (buf[0] != '\0')
+					buf[strlen(buf) - 1] = '\0';
 				ok = !strcmp(buf, *buf == '/' ? pwd->pw_shell :
 								pwd->pw_name);
 			}
Signature · 1 line
2.12.0
maintainer Applied
#1 lore raw
Quoted 2 lines · Tobias Stoeckmann
 login-utils/logindefs.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

Applied, thanks.

Karel

Signature · 2 lines
 Karel Zak  <[email protected]>
 http://karelzak.blogspot.com