From 62eabbf4a9536882fff9dad24f287ea709219f0f Mon Sep 17 00:00:00 2001 From: Karel Zak Date: Thu, 8 Mar 2007 22:35:38 +0100 Subject: [PATCH] login: attempt to run if it has no read/write access to its terminal If you manage to exec login with a userid other than root, and its input / output directed to a terminal for which it does not have read/write access, it will attempt to proceed (and can potentially hang forever -- but this hang has been fixed in a previous commit). It's better to check if we have permissions for terminal rather than do any useless things. From: Jason Vas Dias Signed-off-by: Karel Zak --- login-utils/login.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/login-utils/login.c b/login-utils/login.c index 6ad8fcc8..3948cb7d 100644 --- a/login-utils/login.c +++ b/login-utils/login.c @@ -223,7 +223,8 @@ check_ttyname(char *ttyn) { if (lstat(ttyn, &statbuf) || !S_ISCHR(statbuf.st_mode) - || (statbuf.st_nlink > 1 && strncmp(ttyn, "/dev/", 5))) { + || (statbuf.st_nlink > 1 && strncmp(ttyn, "/dev/", 5)) + || (access(ttyn, R_OK | W_OK) != 0)) { syslog(LOG_ERR, _("FATAL: bad tty")); sleep(1); exit(1); -- 2.39.5