libsa: exit on EOF in ngets

It was possible in some rare circumstances for ngets to behave terribly with
bhyveload and some form of redirecting user input over a pipe.

PR:		198706
Submitted by:	Ivan Krivonos <int0dster@gmail.com>
MFC after:	1 week
This commit is contained in:
Kyle Evans 2018-08-09 02:55:48 +00:00
parent 963aa85d2a
commit 77a52e3f15

View File

@ -44,8 +44,11 @@ ngets(char *buf, int n)
int c; int c;
char *lp; char *lp;
for (lp = buf;;) for (lp = buf;;) {
switch (c = getchar() & 0177) { c = getchar();
if (c == -1)
break;
switch (c & 0177) {
case '\n': case '\n':
case '\r': case '\r':
*lp = '\0'; *lp = '\0';
@ -79,6 +82,7 @@ ngets(char *buf, int n)
putchar(c); putchar(c);
} }
} }
}
/*NOTREACHED*/ /*NOTREACHED*/
} }