Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/netbsd-6]: src/sbin/raidctl Pull up following revision(s) (requested by ...
details: https://anonhg.NetBSD.org/src/rev/74117ffa9d5e
branches: netbsd-6
changeset: 776993:74117ffa9d5e
user: bouyer <bouyer%NetBSD.org@localhost>
date: Sun Nov 15 16:30:38 2015 +0000
description:
Pull up following revision(s) (requested by manu in ticket #1304):
sbin/raidctl/raidctl.c: revision 1.58
Better sanity check numbers given to raidctl(8)
Replace atoi(3) by strtol(3), and check that numbers are valid,
positive, and in int32_t range. The previous lack of check could
silently lead to the same serial being set to all RAID volumes
for instance because given numbers were bigger than INT_MAX. The
consequence is in an awful mess when RAIDframe would mix volumes...
diffstat:
sbin/raidctl/raidctl.c | 34 +++++++++++++++++++++++++++++-----
1 files changed, 29 insertions(+), 5 deletions(-)
diffs (76 lines):
diff -r 52bd51ec47dc -r 74117ffa9d5e sbin/raidctl/raidctl.c
--- a/sbin/raidctl/raidctl.c Sun Nov 15 16:19:16 2015 +0000
+++ b/sbin/raidctl/raidctl.c Sun Nov 15 16:30:38 2015 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: raidctl.c,v 1.55 2011/10/12 16:45:37 christos Exp $ */
+/* $NetBSD: raidctl.c,v 1.55.4.1 2015/11/15 16:30:38 bouyer Exp $ */
/*-
* Copyright (c) 1996, 1997, 1998 The NetBSD Foundation, Inc.
@@ -39,7 +39,7 @@
#include <sys/cdefs.h>
#ifndef lint
-__RCSID("$NetBSD: raidctl.c,v 1.55 2011/10/12 16:45:37 christos Exp $");
+__RCSID("$NetBSD: raidctl.c,v 1.55.4.1 2015/11/15 16:30:38 bouyer Exp $");
#endif
@@ -85,6 +85,7 @@
static void get_time_string(char *, int);
static void rf_output_pmstat(int, int);
static void rf_pm_configure(int, int, char *, int[]);
+static unsigned int _strtoud(char *);
int verbose;
@@ -183,7 +184,7 @@
break;
case 'I':
action = RAIDFRAME_INIT_LABELS;
- serial_number = atoi(optarg);
+ serial_number = _strtoud(optarg);
num_options++;
break;
case 'm':
@@ -195,11 +196,11 @@
action = RAIDFRAME_PARITYMAP_SET_DISABLE;
parityconf = strdup(optarg);
num_options++;
- /* XXXjld: should rf_pm_configure do the atoi()s? */
+ /* XXXjld: should rf_pm_configure do the strtol()s? */
i = 0;
while (i < 3 && optind < argc &&
isdigit((int)argv[optind][0]))
- parityparams[i++] = atoi(argv[optind++]);
+ parityparams[i++] = _strtoud(argv[optind++]);
while (i < 3)
parityparams[i++] = 0;
break;
@@ -1155,3 +1156,26 @@
exit(1);
/* NOTREACHED */
}
+
+static unsigned int
+_strtoud(char *str)
+{
+ long num;
+ char *ep;
+
+ errno = 0;
+ num = strtol(str, &ep, 10);
+ if (str[0] == '\0' || *ep != '\0')
+ errx(1, "Not a number: %s", str);
+
+ if (errno)
+ err(1, "Inavlid number %s", str);
+
+ if (num < 0)
+ errx(1, "Negative number: %s", str);
+
+ if (num > INT_MAX)
+ errx(1, "Number too large: %s", str);
+
+ return (unsigned int)num;
+}
Home |
Main Index |
Thread Index |
Old Index