This is a simple patch to protect users from silly mistakes (I've done
it...).

After a quick glance at tip/cu man page, I had mixed tip and cu options
(misinterpreting tip' one, BTW) ending with this:

cu -speed 115200 -l /dev/ttyU0

and obtained a puzzling garbage on the screen, since the speed was in
fact set after "-s" from "peed", ended being 0 (thanks to atoi(3)) and 
so being finally reset to the default, the 115200 being, for itself,
interpreted as a phone number...

Since I spent some time verifying cabling etc. before realizing the
mistake and that it was just the incorrect baud rate, it is worth
intercepting nonsense (0 is still a valid speed in order to keep the
traditional behavior).

-- 
        Thierry Laronde <tlaronde +AT+ polynum +dot+ com>
                     http://www.kergis.com/
                       http://www.sbfa.fr/
Key fingerprint = 0FF7 E906 FBAF FE95 FD89  250D 52B1 AE95 6006 F40C
Index: cu.c
===================================================================
RCS file: /cvsroot/src/usr.bin/tip/cu.c,v
retrieving revision 1.23
diff -u -r1.23 cu.c
--- cu.c        3 Jan 2016 15:38:29 -0000       1.23
+++ cu.c        17 Aug 2019 15:44:25 -0000
@@ -140,7 +140,14 @@
                        useresc = -1;
                        break;
                case 's':
-                       BR = atoi(optarg);
+                       {
+                               char *ep;
+
+                               errno = 0;
+                               BR = strtol(optarg, &ep, 0);
+                               if (ep == optarg || *ep != '\0' || errno != 0 
|| BR < 0)
+                                       errx(3,"incorrect speed (wrong number 
or option)");
+                       }
                        break;
                case 'h':
                        HD = TRUE;

Reply via email to