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
This commit is contained in:
Eric van Gyzen 2019-11-11 17:41:52 +00:00
parent 45fceedf87
commit 552117964a
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=354624

View File

@ -252,7 +252,6 @@ main(int argc, char *argv[])
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)