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)
_______________________________________________
[email protected] mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "[email protected]"

Reply via email to