From owner-svn-src-head@freebsd.org Mon Nov 11 17:41:53 2019 Return-Path: Delivered-To: svn-src-head@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 437161BA626; Mon, 11 Nov 2019 17:41:53 +0000 (UTC) (envelope-from vangyzen@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) server-signature RSA-PSS (4096 bits) client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 47BdV9121Tz4RRX; Mon, 11 Nov 2019 17:41:53 +0000 (UTC) (envelope-from vangyzen@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 07DB11AE99; Mon, 11 Nov 2019 17:41:53 +0000 (UTC) (envelope-from vangyzen@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id xABHfqKt001825; Mon, 11 Nov 2019 17:41:52 GMT (envelope-from vangyzen@FreeBSD.org) Received: (from vangyzen@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id xABHfqth001824; Mon, 11 Nov 2019 17:41:52 GMT (envelope-from vangyzen@FreeBSD.org) Message-Id: <201911111741.xABHfqth001824@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: vangyzen set sender to vangyzen@FreeBSD.org using -f From: Eric van Gyzen Date: Mon, 11 Nov 2019 17:41:52 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r354624 - head/usr.bin/tip/tip X-SVN-Group: head X-SVN-Commit-Author: vangyzen X-SVN-Commit-Paths: head/usr.bin/tip/tip X-SVN-Commit-Revision: 354624 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 11 Nov 2019 17:41:53 -0000 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)