From 77a52e3f1589b3fef91874b3d6ecac99f3117c8e Mon Sep 17 00:00:00 2001 From: Kyle Evans Date: Thu, 9 Aug 2018 02:55:48 +0000 Subject: [PATCH] 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 MFC after: 1 week --- stand/libsa/gets.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/stand/libsa/gets.c b/stand/libsa/gets.c index 9172ffc1328f..206a6d25fcea 100644 --- a/stand/libsa/gets.c +++ b/stand/libsa/gets.c @@ -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*/ }