From f648dfd92939b4015c42637db3ca68024a2b764f Mon Sep 17 00:00:00 2001 From: Yaroslav Tykhiy Date: Fri, 6 Jun 2003 14:36:41 +0000 Subject: [PATCH] Fix some minor bugs, namely: - Initialize "rval", which would be used uninitialized if al or pl options were set. - Don't pass an empty string to login(1) as a user name (this could be triggered by entering a name and then killing it with backspace or ^U.) - Don't loop endlessly if the al option specifies a bogus (i.e., not alphanumeric) auto-login name. - Don't pass a bogus user name to login(1) if a good name were entered and then killed with ^U. - Exit with status 0, not 1, on receiving an EOF character, since it's not a error condition. MFC after: 1 week --- libexec/getty/main.c | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/libexec/getty/main.c b/libexec/getty/main.c index aaff70ca385..5410ef7c419 100644 --- a/libexec/getty/main.c +++ b/libexec/getty/main.c @@ -344,6 +344,8 @@ main(int argc, char *argv[]) signal(SIGALRM, dingdong); alarm(TO); } + + rval = 0; if (AL) { const char *p = AL; char *q = name; @@ -374,12 +376,20 @@ main(int argc, char *argv[]) oflush(); alarm(0); signal(SIGALRM, SIG_DFL); + if (name[0] == '\0') + continue; if (name[0] == '-') { puts("user names may not start with '-'."); continue; } - if (!(upper || lower || digit)) - continue; + if (!(upper || lower || digit)) { + if (AL) { + syslog(LOG_ERR, + "invalid auto-login name: %s", AL); + exit(1); + } else + continue; + } set_flags(2); if (crmod) { tmode.c_iflag |= ICRNL; @@ -564,7 +574,7 @@ getname(void) } if (c == EOT || c == CTRL('d')) - exit(1); + exit(0); if (c == '\r' || c == '\n' || np >= &name[sizeof name-1]) { putf("\r\n"); break; @@ -590,6 +600,7 @@ getname(void) else if (np > name) puts(" \r"); prompt(); + digit = lower = upper = 0; np = name; continue; } else if (isdigit(c))