Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/usr.sbin/usbdevs Use strtoi instead of atoi() to catch bad i...
details: https://anonhg.NetBSD.org/src/rev/db30edde19f4
branches: trunk
changeset: 465534:db30edde19f4
user: christos <christos%NetBSD.org@localhost>
date: Wed Nov 27 17:56:08 2019 +0000
description:
Use strtoi instead of atoi() to catch bad input (Alexander Kuleshov)
diffstat:
usr.sbin/usbdevs/usbdevs.c | 17 ++++++++++++-----
1 files changed, 12 insertions(+), 5 deletions(-)
diffs (57 lines):
diff -r f65ca2526969 -r db30edde19f4 usr.sbin/usbdevs/usbdevs.c
--- a/usr.sbin/usbdevs/usbdevs.c Wed Nov 27 15:58:12 2019 +0000
+++ b/usr.sbin/usbdevs/usbdevs.c Wed Nov 27 17:56:08 2019 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: usbdevs.c,v 1.39 2019/11/12 07:41:50 mrg Exp $ */
+/* $NetBSD: usbdevs.c,v 1.40 2019/11/27 17:56:08 christos Exp $ */
/*
* Copyright (c) 1998 The NetBSD Foundation, Inc.
@@ -31,7 +31,7 @@
#include <sys/cdefs.h>
#ifndef lint
-__RCSID("$NetBSD: usbdevs.c,v 1.39 2019/11/12 07:41:50 mrg Exp $");
+__RCSID("$NetBSD: usbdevs.c,v 1.40 2019/11/27 17:56:08 christos Exp $");
#endif
#include <sys/types.h>
@@ -48,6 +48,7 @@
#include <langinfo.h>
#include <iconv.h>
#include <ctype.h>
+#include <inttypes.h>
#include <dev/usb/usb.h>
@@ -367,7 +368,7 @@
int
main(int argc, char **argv)
{
- int ch, i, f;
+ int ch, i, f, error;
char buf[50];
char *dev = NULL;
int addr = -1;
@@ -376,7 +377,13 @@
while ((ch = getopt(argc, argv, "a:df:v?")) != -1) {
switch(ch) {
case 'a':
- addr = atoi(optarg);
+ addr = strtoi(optarg, NULL, 10, 0, USB_MAX_DEVICES - 1,
+ &error);
+ if (error) {
+ errc(EXIT_FAILURE, error,
+ "Bad value for device address: `%s'",
+ optarg);
+ }
break;
case 'd':
showdevs++;
@@ -429,5 +436,5 @@
else
err(1, "%s", dev);
}
- exit(EXIT_SUCCESS);
+ return EXIT_SUCCESS;
}
Home |
Main Index |
Thread Index |
Old Index