svn commit: r337523 - head/stand/libsa

Kyle Evans kevans at FreeBSD.org
Thu Aug 9 02:55:49 UTC 2018


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 <int0dster at 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*/
 }
 


More information about the svn-src-all mailing list