aboutsummaryrefslogtreecommitdiff
path: root/usr.bin/lock/lock.c
diff options
context:
space:
mode:
authorColin Percival <cperciva@FreeBSD.org>2004-01-22 04:24:15 +0000
committerColin Percival <cperciva@FreeBSD.org>2004-01-22 04:24:15 +0000
commit54ca359425fa8db3734798f19d6bf822e4fd2096 (patch)
treee48fdb610de4698d48e6fecbf521c827d2d0da5e /usr.bin/lock/lock.c
parentc66380c1228f634cdd0eae2c949ed07a43558fa4 (diff)
downloadsrc-54ca359425fa8db3734798f19d6bf822e4fd2096.tar.gz
src-54ca359425fa8db3734798f19d6bf822e4fd2096.zip
Two fixes here:
1. If fgets fails, don't go into an infinite cpu-intensive loop. Instead, check to see if the terminal still exists, and sleep(1) otherwise. 2. When we check to see if the terminal still exists, make sure we're not mislead by EINTR. This could have been a security issue, but fortunately the current implementation of tcgetattr doesn't EINTR. PR: bin/60758 Approved by: rwatson (mentor)
Notes
Notes: svn path=/head/; revision=124824
Diffstat (limited to 'usr.bin/lock/lock.c')
-rw-r--r--usr.bin/lock/lock.c6
1 files changed, 4 insertions, 2 deletions
diff --git a/usr.bin/lock/lock.c b/usr.bin/lock/lock.c
index 15d994147e1f..3b19e35bbe1c 100644
--- a/usr.bin/lock/lock.c
+++ b/usr.bin/lock/lock.c
@@ -63,6 +63,7 @@ __FBSDID("$FreeBSD$");
#include <sys/consio.h>
#include <err.h>
#include <ctype.h>
+#include <errno.h>
#include <pwd.h>
#include <stdio.h>
#include <stdlib.h>
@@ -212,7 +213,7 @@ main(int argc, char **argv)
if (!fgets(s, sizeof(s), stdin)) {
clearerr(stdin);
hi(0);
- continue;
+ goto tryagain;
}
if (usemine) {
s[strlen(s) - 1] = '\0';
@@ -226,7 +227,8 @@ main(int argc, char **argv)
if (getuid() == 0)
syslog(LOG_NOTICE, "%d ROOT UNLOCK FAILURE%s (%s on %s)",
failures, failures > 1 ? "S": "", ttynam, hostname);
- if (tcgetattr(0, &ntty))
+tryagain:
+ if (tcgetattr(0, &ntty) && (errno != EINTR))
exit(1);
sleep(1); /* to discourage guessing */
}