summaryrefslogtreecommitdiffstats
path: root/misc.c
diff options
context:
space:
mode:
authordtucker@openbsd.org <dtucker@openbsd.org>2017-12-05 23:59:47 +0000
committerDarren Tucker <dtucker@zip.com.au>2017-12-07 11:49:00 +1100
commit609d96b3d58475a15b2eb6b3d463f2c5d8e510c0 (patch)
treebe75a3c395010d0ccf6e5c07e46e4e826203a221 /misc.c
parent168ecec13f9d7cb80c07df3bf7d414f4e4165e84 (diff)
upstream commit
Replace atoi and strtol conversions for integer arguments to config keywords with a checking wrapper around strtonum. This will prevent and flag invalid and negative arguments to these keywords. ok djm@ OpenBSD-Commit-ID: 99ae3981f3d608a219ccb8d2fff635ae52c17998
Diffstat (limited to 'misc.c')
-rw-r--r--misc.c16
1 files changed, 15 insertions, 1 deletions
diff --git a/misc.c b/misc.c
index dfa0bb33..3d6bc356 100644
--- a/misc.c
+++ b/misc.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: misc.c,v 1.119 2017/11/25 06:46:22 dtucker Exp $ */
+/* $OpenBSD: misc.c,v 1.120 2017/12/05 23:59:47 dtucker Exp $ */
/*
* Copyright (c) 2000 Markus Friedl. All rights reserved.
* Copyright (c) 2005,2006 Damien Miller. All rights reserved.
@@ -2112,3 +2112,17 @@ bad:
*errstr = errbuf;
return 0;
}
+
+const char *
+atoi_err(const char *nptr, int *val)
+{
+ const char *errstr = NULL;
+ long long num;
+
+ if (nptr == NULL || *nptr == '\0')
+ return "missing";
+ num = strtonum(nptr, 0, INT_MAX, &errstr);
+ if (errstr == NULL)
+ *val = (int)num;
+ return errstr;
+}