summaryrefslogtreecommitdiffstats
path: root/usr.sbin/gpioctl/gpioctl.c
diff options
context:
space:
mode:
authorderaadt <deraadt@openbsd.org>2007-03-18 16:16:56 +0000
committerderaadt <deraadt@openbsd.org>2007-03-18 16:16:56 +0000
commitedf9ea1aa554938fb9fd08393c257cc73e0172c7 (patch)
treeb4c18f1fdb905b45c8e727eb3e14b3d005c7734b /usr.sbin/gpioctl/gpioctl.c
parentallow this to build w/ cross-tools thru providing proper hostcflags; found by rainor's work (diff)
downloadwireguard-openbsd-edf9ea1aa554938fb9fd08393c257cc73e0172c7.tar.xz
wireguard-openbsd-edf9ea1aa554938fb9fd08393c257cc73e0172c7.zip
use strtonum() to avoid out of range values, way simpler than the
12-line song and dance that standard functions need; bret.lambert@gmail
Diffstat (limited to 'usr.sbin/gpioctl/gpioctl.c')
-rw-r--r--usr.sbin/gpioctl/gpioctl.c13
1 files changed, 7 insertions, 6 deletions
diff --git a/usr.sbin/gpioctl/gpioctl.c b/usr.sbin/gpioctl/gpioctl.c
index 50e9ea09cf3..0825af6d66e 100644
--- a/usr.sbin/gpioctl/gpioctl.c
+++ b/usr.sbin/gpioctl/gpioctl.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: gpioctl.c,v 1.4 2005/11/17 10:18:18 grange Exp $ */
+/* $OpenBSD: gpioctl.c,v 1.5 2007/03/18 16:16:56 deraadt Exp $ */
/*
* Copyright (c) 2004 Alexander Yurchenko <grange@openbsd.org>
*
@@ -22,6 +22,7 @@
#include <sys/types.h>
#include <sys/gpio.h>
#include <sys/ioctl.h>
+#include <sys/limits.h>
#include <err.h>
#include <fcntl.h>
@@ -61,7 +62,7 @@ int
main(int argc, char *argv[])
{
int ch;
- char *ep;
+ const char *errstr;
int do_ctl = 0;
int pin = 0, value = 0;
@@ -84,8 +85,8 @@ main(int argc, char *argv[])
argv += optind;
if (argc > 0) {
- pin = strtol(argv[0], &ep, 10);
- if (*argv[0] == '\0' || *ep != '\0' || pin < 0)
+ pin = strtonum(argv[0], 0, INT_MAX, &errstr);
+ if (errstr)
errx(1, "%s: invalid pin", argv[0]);
}
@@ -103,8 +104,8 @@ main(int argc, char *argv[])
if (do_ctl) {
pinctl(pin, argv + 1, argc - 1);
} else {
- value = strtol(argv[1], &ep, 10);
- if (*argv[1] == '\0' || *ep != '\0')
+ value = strtonum(argv[1], INT_MIN, INT_MAX, &errstr);
+ if (errstr)
errx(1, "%s: invalid value", argv[1]);
pinwrite(pin, value);
}