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

Reply via email to