Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 3 Dec 2019 22:57:11 +0000 (UTC)
From:      Eric van Gyzen <vangyzen@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-12@freebsd.org
Subject:   svn commit: r355369 - stable/12/usr.bin/tip/tip
Message-ID:  <201912032257.xB3MvBTH010875@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: vangyzen
Date: Tue Dec  3 22:57:10 2019
New Revision: 355369
URL: https://svnweb.freebsd.org/changeset/base/355369

Log:
  MFC r354624
  
  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.
  
  Sponsored by:	Dell EMC Isilon

Modified:
  stable/12/usr.bin/tip/tip/tip.c
Directory Properties:
  stable/12/   (props changed)

Modified: stable/12/usr.bin/tip/tip/tip.c
==============================================================================
--- stable/12/usr.bin/tip/tip/tip.c	Tue Dec  3 22:54:24 2019	(r355368)
+++ stable/12/usr.bin/tip/tip/tip.c	Tue Dec  3 22:57:10 2019	(r355369)
@@ -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?201912032257.xB3MvBTH010875>