From 88ec83cd5a58b8e59b6af3793bb4d6783b290735 Mon Sep 17 00:00:00 2001 From: kevans Date: Mon, 20 Aug 2018 00:49:06 +0000 Subject: [PATCH] MFC r337523: 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 --- 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 7d54b000177..e8466dd15c3 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*/ } -- 2.45.0