summaryrefslogtreecommitdiff
path: root/usr.bin/tip
diff options
context:
space:
mode:
authorTodd C. Miller <millert@cvs.openbsd.org>2006-11-06 19:37:22 +0000
committerTodd C. Miller <millert@cvs.openbsd.org>2006-11-06 19:37:22 +0000
commitcd76cad7a317f7d476d96a0d65b080b5e3f8c8d5 (patch)
tree3c8699acd570322eb822ff05f941af204c9e403d /usr.bin/tip
parent3d7c4e2b9c993f8cdaa8bca7b0149dbee32b9325 (diff)
Replace -### with -s### pre-getopt() and use strtonum()
instead of strtol() when parsing the speed string. Closes PR 5222.
Diffstat (limited to 'usr.bin/tip')
-rw-r--r--usr.bin/tip/cu.c54
-rw-r--r--usr.bin/tip/tip.h3
2 files changed, 37 insertions, 20 deletions
diff --git a/usr.bin/tip/cu.c b/usr.bin/tip/cu.c
index 9cff32bdc33..bb7183d1c41 100644
--- a/usr.bin/tip/cu.c
+++ b/usr.bin/tip/cu.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: cu.c,v 1.19 2006/05/25 08:41:52 jmc Exp $ */
+/* $OpenBSD: cu.c,v 1.20 2006/11/06 19:37:21 millert Exp $ */
/* $NetBSD: cu.c,v 1.5 1997/02/11 09:24:05 mrg Exp $ */
/*
@@ -34,7 +34,7 @@
#if 0
static char sccsid[] = "@(#)cu.c 8.1 (Berkeley) 6/6/93";
#endif
-static const char rcsid[] = "$OpenBSD: cu.c,v 1.19 2006/05/25 08:41:52 jmc Exp $";
+static const char rcsid[] = "$OpenBSD: cu.c,v 1.20 2006/11/06 19:37:21 millert Exp $";
#endif /* not lint */
#include "tip.h"
@@ -48,8 +48,7 @@ void
cumain(int argc, char *argv[])
{
int ch, i, parity;
- long l;
- char *cp;
+ const char *errstr;
static char sbuf[12];
if (argc < 2)
@@ -57,7 +56,35 @@ cumain(int argc, char *argv[])
CU = DV = NOSTR;
BR = DEFBR;
parity = 0; /* none */
- while ((ch = getopt(argc, argv, "a:l:s:htoe0123456789")) != -1) {
+
+ /*
+ * Convert obsolecent -### speed to modern -s### syntax which
+ * getopt() can handle.
+ */
+ for (i = 1; i < argc; i++) {
+ if (argv[i][0] == '-') {
+ switch (argv[i][1]) {
+ case '0': case '1': case '2': case '3': case '4':
+ case '5': case '6': case '7': case '8': case '9':
+ ch = snprintf(sbuf, sizeof(sbuf), "-s%s",
+ &argv[i][1]);
+ if (ch <= 0 || ch >= sizeof(sbuf)) {
+ errx(3, "invalid speed: %s",
+ &argv[i][1]);
+ }
+ argv[i] = sbuf;
+ break;
+ case '-':
+ /* if we get "--" stop processing args */
+ if (argv[i][2] == '\0')
+ goto getopt;
+ break;
+ }
+ }
+ }
+
+getopt:
+ while ((ch = getopt(argc, argv, "a:l:s:htoe")) != -1) {
switch (ch) {
case 'a':
CU = optarg;
@@ -75,13 +102,9 @@ cumain(int argc, char *argv[])
asprintf(&DV, "/dev/%s", optarg);
break;
case 's':
- l = strtol(optarg, &cp, 10);
- if (*cp != '\0' || l < 0 || l >= INT_MAX) {
- fprintf(stderr, "%s: unsupported speed %s\n",
- __progname, optarg);
- exit(3);
- }
- BR = (int)l;
+ BR = (int)strtonum(optarg, 0, INT_MAX, &errstr);
+ if (errstr)
+ errx(3, "speed is %s: %s", errstr, optarg);
break;
case 'h':
setboolean(value(LECHO), TRUE);
@@ -102,13 +125,6 @@ cumain(int argc, char *argv[])
else
parity = -1; /* even */
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;
- break;
default:
cuusage();
break;
diff --git a/usr.bin/tip/tip.h b/usr.bin/tip/tip.h
index 975590029ac..dc42310f251 100644
--- a/usr.bin/tip/tip.h
+++ b/usr.bin/tip/tip.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: tip.h,v 1.27 2006/08/18 03:06:18 jason Exp $ */
+/* $OpenBSD: tip.h,v 1.28 2006/11/06 19:37:21 millert Exp $ */
/* $NetBSD: tip.h,v 1.7 1997/04/20 00:02:46 mellon Exp $ */
/*
@@ -53,6 +53,7 @@
#include <setjmp.h>
#include <unistd.h>
#include <errno.h>
+#include <err.h>
#include <limits.h>
/*