Author: kevans
Date: Thu Aug  9 02:55:48 2018
New Revision: 337523
URL: https://svnweb.freebsd.org/changeset/base/337523

Log:
  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 <int0ds...@gmail.com>
  MFC after:    1 week

Modified:
  head/stand/libsa/gets.c

Modified: head/stand/libsa/gets.c
==============================================================================
--- head/stand/libsa/gets.c     Thu Aug  9 02:47:22 2018        (r337522)
+++ head/stand/libsa/gets.c     Thu Aug  9 02:55:48 2018        (r337523)
@@ -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*/
 }
 
_______________________________________________
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"

Reply via email to