summaryrefslogtreecommitdiff
path: root/usr.bin
diff options
context:
space:
mode:
authorTed Unangst <tedu@cvs.openbsd.org>2007-04-07 23:20:20 +0000
committerTed Unangst <tedu@cvs.openbsd.org>2007-04-07 23:20:20 +0000
commit9f94e9d55e37418c5d78c0f9926aa6673f1fa779 (patch)
treece11e43f274a1a9ddcf81d95272402d889978d83 /usr.bin
parentc6b764f7a9d018ac40e2d03f931cea130b13d8ae (diff)
use strtonum, from jason dixon
Diffstat (limited to 'usr.bin')
-rw-r--r--usr.bin/fold/fold.c22
-rw-r--r--usr.bin/fstat/fstat.c12
-rw-r--r--usr.bin/ftp/main.c13
3 files changed, 30 insertions, 17 deletions
diff --git a/usr.bin/fold/fold.c b/usr.bin/fold/fold.c
index 42588420456..50d8babc2c3 100644
--- a/usr.bin/fold/fold.c
+++ b/usr.bin/fold/fold.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: fold.c,v 1.10 2003/09/26 22:22:50 tedu Exp $ */
+/* $OpenBSD: fold.c,v 1.11 2007/04/07 23:20:18 tedu Exp $ */
/* $NetBSD: fold.c,v 1.6 1995/09/01 01:42:44 jtc Exp $ */
/*-
@@ -43,7 +43,7 @@ static char copyright[] =
#if 0
static char sccsid[] = "@(#)fold.c 8.1 (Berkeley) 6/6/93";
#endif
-static char rcsid[] = "$OpenBSD: fold.c,v 1.10 2003/09/26 22:22:50 tedu Exp $";
+static char rcsid[] = "$OpenBSD: fold.c,v 1.11 2007/04/07 23:20:18 tedu Exp $";
#endif /* not lint */
#include <stdio.h>
@@ -51,6 +51,7 @@ static char rcsid[] = "$OpenBSD: fold.c,v 1.10 2003/09/26 22:22:50 tedu Exp $";
#include <string.h>
#include <unistd.h>
#include <err.h>
+#include <limits.h>
#define DEFLINEWIDTH 80
@@ -65,6 +66,8 @@ main(int argc, char *argv[])
int ch;
int width;
char *p;
+ char *w;
+ const char *errstr;
width = -1;
while ((ch = getopt(argc, argv, "0123456789bsw:")) != -1)
@@ -76,17 +79,24 @@ main(int argc, char *argv[])
split_words = 1;
break;
case 'w':
- if ((width = atoi(optarg)) <= 0)
- errx(1, "illegal width value.");
+ width = strtonum(optarg, 1, INT_MAX, &errstr);
+ if (errstr != NULL)
+ errx(1, "illegal width value, %s: %s", errstr,
+ optarg);
break;
case '0': case '1': case '2': case '3': case '4':
case '5': case '6': case '7': case '8': case '9':
if (width == -1) {
p = argv[optind - 1];
if (p[0] == '-' && p[1] == ch && !p[2])
- width = atoi(++p);
+ w = ++p;
else
- width = atoi(argv[optind] + 1);
+ w = argv[optind] + 1;
+
+ width = strtonum(w, 1, INT_MAX, &errstr);
+ if (errstr != NULL)
+ errx(1, "illegal width value, %s: %s",
+ errstr, optarg);
}
break;
default:
diff --git a/usr.bin/fstat/fstat.c b/usr.bin/fstat/fstat.c
index ffb5d6223db..72fe4fd44ef 100644
--- a/usr.bin/fstat/fstat.c
+++ b/usr.bin/fstat/fstat.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: fstat.c,v 1.57 2006/06/19 22:31:20 deraadt Exp $ */
+/* $OpenBSD: fstat.c,v 1.58 2007/04/07 23:20:19 tedu Exp $ */
/*-
* Copyright (c) 1988, 1993
@@ -37,7 +37,7 @@ static char copyright[] =
#ifndef lint
/*static char sccsid[] = "from: @(#)fstat.c 8.1 (Berkeley) 6/6/93";*/
-static char *rcsid = "$OpenBSD: fstat.c,v 1.57 2006/06/19 22:31:20 deraadt Exp $";
+static char *rcsid = "$OpenBSD: fstat.c,v 1.58 2007/04/07 23:20:19 tedu Exp $";
#endif /* not lint */
#include <sys/param.h>
@@ -174,6 +174,7 @@ main(int argc, char *argv[])
int arg, ch, what;
char *memf, *nlistf;
char buf[_POSIX2_LINE_MAX];
+ const char *errstr;
int cnt;
gid_t gid;
@@ -201,12 +202,13 @@ main(int argc, char *argv[])
case 'p':
if (pflg++)
usage();
- if (!isdigit(*optarg)) {
- warnx( "-p requires a process id");
+ arg = strtonum(optarg, 0, INT_MAX, &errstr);
+ if (errstr != NULL) {
+ warnx("-p requires a process id, %s: %s",
+ errstr, optarg);
usage();
}
what = KERN_PROC_PID;
- arg = atoi(optarg);
break;
case 's':
sflg = 1;
diff --git a/usr.bin/ftp/main.c b/usr.bin/ftp/main.c
index 51590c9ed7c..708e929971b 100644
--- a/usr.bin/ftp/main.c
+++ b/usr.bin/ftp/main.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: main.c,v 1.61 2006/05/16 16:20:42 deraadt Exp $ */
+/* $OpenBSD: main.c,v 1.62 2007/04/07 23:20:18 tedu Exp $ */
/* $NetBSD: main.c,v 1.24 1997/08/18 10:20:26 lukem Exp $ */
/*
@@ -66,7 +66,7 @@ static const char copyright[] =
#endif /* not lint */
#if !defined(lint) && !defined(SMALL)
-static const char rcsid[] = "$OpenBSD: main.c,v 1.61 2006/05/16 16:20:42 deraadt Exp $";
+static const char rcsid[] = "$OpenBSD: main.c,v 1.62 2007/04/07 23:20:18 tedu Exp $";
#endif /* not lint and not SMALL */
/*
@@ -96,6 +96,7 @@ main(volatile int argc, char *argv[])
struct passwd *pw = NULL;
char *cp, homedir[MAXPATHLEN];
char *outfile = NULL;
+ const char *errstr;
int dumb_terminal = 0;
ftpport = "ftp";
@@ -239,10 +240,10 @@ main(volatile int argc, char *argv[])
break;
case 'r':
- if (isdigit(*optarg))
- retry_connect = atoi(optarg);
- else
- errx(1, "-r requires numeric argument");
+ retry_connect = strtonum(optarg, 0, INT_MAX, &errstr);
+ if (errstr != NULL)
+ errx(1, "retry amount is %s: %s", errstr,
+ optarg);
break;
case 't':