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:
kevans 2018-08-09 02:55:48 +00:00
parent 76ffe38cc2
commit d8e33fe91d

View File

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