user/5222: cu(1) -### doesn't work as described. Patch.

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

user/5222: cu(1) -### doesn't work as described. Patch.

Stuart Henderson-5
>Number:         5222
>Category:       user
>Synopsis:       cu(1) -### doesn't work as described.
>Confidential:   yes
>Severity:       non-critical
>Priority:       low
>Responsible:    bugs
>State:          open
>Quarter:        
>Keywords:      
>Date-Required:
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Mon Sep 04 16:50:01 GMT 2006
>Closed-Date:
>Last-Modified:
>Originator:     Stuart Henderson
>Release:        OpenBSD 4.0 (GENERIC) #681: Mon Aug 28 16:06:55 MDT 2006
>Organization:
net
>Environment:
       
        System      : OpenBSD 4.0
        Architecture: OpenBSD.amd64
        Machine     : amd64
>Description:
       
According to cu(1), command line option -### is equivalent to -s ###
it is not.

>How-To-Repeat:
$ cu -s 19200 -l /dev/cuaU0
$ cu -19200 -l /dev/cuaU0

These should be identical; actually the second format connects at
the default speed (normally 9600).

>Fix:
       
NetBSD imported the option handling code with a fix for this in
http://cvsweb.netbsd.org/bsdweb.cgi/src/usr.bin/tip/cu.c#rev1.10
They use atoi(); this diff applies to OpenBSD tree and uses strtol
following the format used few lines earlier in the code for -s
handling.

Index: usr.bin/tip/cu.c
===================================================================
RCS file: /data/cvsroot/OpenBSD/src/usr.bin/tip/cu.c,v
retrieving revision 1.19
diff -u -r1.19 cu.c
--- usr.bin/tip/cu.c 25 May 2006 08:41:52 -0000 1.19
+++ usr.bin/tip/cu.c 4 Sep 2006 16:21:44 -0000
@@ -50,7 +50,7 @@
  int ch, i, parity;
  long l;
  char *cp;
- static char sbuf[12];
+ static char sbuf[12], brbuf[16];
 
  if (argc < 2)
  cuusage();
@@ -104,10 +104,15 @@
  break;
  case '0': case '1': case '2': case '3': case '4':
  case '5': case '6': case '7': case '8': case '9':
- if (CU)
- CU[strlen(CU)-1] = ch;
- if (DV)
- DV[strlen(DV)-1] = ch;
+ snprintf(brbuf, sizeof(brbuf) -1, "%s%c",
+ brbuf, ch);
+ l = strtol(brbuf, &cp, 10);
+ if (*cp != '\0' || l < 0 || l >= INT_MAX) {
+ fprintf(stderr, "%s: unsupported speed %s\n",
+    __progname, brbuf);
+ exit(3);
+ }
+ BR = (int)l;
  break;
  default:
  cuusage();

There's a minor problem with this patch: since speed is built up
char-by-char, exceeding INT_MAX immediately displays "unsupported
speed" as far as it's got, rather than with the whole string:

$ ./cu -123456789012345 -l /dev/cuaU0    
cu: unsupported speed 12345678901

I'm not exactly a programmer so I didn't attempt to avoid this,
anyway imho behaviour with the patch is significantly better than
without.

This probably also applies to FreeBSD who use OpenBSD's tip/cu.


>Release-Note:
>Audit-Trail:
>Unformatted: