Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 11 Nov 2019 17:41:52 +0000 (UTC)
From:      Eric van Gyzen <vangyzen@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r354624 - head/usr.bin/tip/tip
Message-ID:  <201911111741.xABHfqth001824@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: vangyzen
Date: Mon Nov 11 17:41:52 2019
New Revision: 354624
URL: https://svnweb.freebsd.org/changeset/base/354624

Log:
  tip/cu: check for EOF on input on the local side
  
  If cu reads an EOF on the input side, it goes into a tight loop
  sending a garbage byte to the remote.  With this change, it exits
  gracefully, along with its child.
  
  MFC after:	2 weeks
  Sponsored by:	Dell EMC Isilon

Modified:
  head/usr.bin/tip/tip/tip.c

Modified: head/usr.bin/tip/tip/tip.c
==============================================================================
--- head/usr.bin/tip/tip/tip.c	Mon Nov 11 17:36:57 2019	(r354623)
+++ head/usr.bin/tip/tip/tip.c	Mon Nov 11 17:41:52 2019	(r354624)
@@ -252,7 +252,6 @@ cucommon:
 		tipin();
 	else
 		tipout();
-	/*NOTREACHED*/
 	exit(0);
 }
 
@@ -402,11 +401,16 @@ tipin(void)
 	}
 
 	while (1) {
-		gch = getchar()&STRIP_PAR;
-		/* XXX does not check for EOF */
+		gch = getchar();
+		if (gch == EOF)
+			return;
+		gch = gch & STRIP_PAR;
 		if ((gch == character(value(ESCAPE))) && bol) {
 			if (!noesc) {
-				if (!(gch = escape()))
+				gch = escape();
+				if (gch == EOF)
+					return;
+				if (gch == 0)
 					continue;
 			}
 		} else if (!cumode && gch == character(value(RAISECHAR))) {
@@ -420,7 +424,10 @@ tipin(void)
 				printf("\r\n");
 			continue;
 		} else if (!cumode && gch == character(value(FORCE)))
-			gch = getchar()&STRIP_PAR;
+			gch = getchar();
+			if (gch == EOF)
+				return;
+			gch = gch & STRIP_PAR;
 		bol = any(gch, value(EOL));
 		if (boolean(value(RAISE)) && islower(gch))
 			gch = toupper(gch);
@@ -444,8 +451,10 @@ escape(void)
 	esctable_t *p;
 	char c = character(value(ESCAPE));
 
-	gch = (getchar()&STRIP_PAR);
-	/* XXX does not check for EOF */
+	gch = getchar();
+	if (gch == EOF)
+		return (EOF);
+	gch = gch & STRIP_PAR;
 	for (p = etable; p->e_char; p++)
 		if (p->e_char == gch) {
 			if ((p->e_flags&PRIV) && uid)



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201911111741.xABHfqth001824>