svn commit: r338077 - stable/11/stand/libsa

Kyle Evans kevans at FreeBSD.org
Mon Aug 20 00:49:07 UTC 2018


Author: kevans
Date: Mon Aug 20 00:49:06 2018
New Revision: 338077
URL: https://svnweb.freebsd.org/changeset/base/338077

Log:
  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

Modified:
  stable/11/stand/libsa/gets.c
Directory Properties:
  stable/11/   (props changed)

Modified: stable/11/stand/libsa/gets.c
==============================================================================
--- stable/11/stand/libsa/gets.c	Mon Aug 20 00:47:51 2018	(r338076)
+++ stable/11/stand/libsa/gets.c	Mon Aug 20 00:49:06 2018	(r338077)
@@ -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-stable-11 mailing list