summaryrefslogtreecommitdiff
path: root/usr.sbin/bind/bin/dig
diff options
context:
space:
mode:
authorFlorian Obser <florian@cvs.openbsd.org>2020-02-05 06:41:47 +0000
committerFlorian Obser <florian@cvs.openbsd.org>2020-02-05 06:41:47 +0000
commitecfb0c96e53b6c1b6d4584128fa31f9746d7f8f3 (patch)
tree269278c1eb7ca35e7b068ac432c12e55a93b4fc3 /usr.sbin/bind/bin/dig
parent17b193eb48fa7965083d1e6534c0485f9168ed0d (diff)
Replace atoi with strtonum for stricter and safer integer parsing.
-N ndots: 0, INT_MAX The upper limit is a bit silly, everything bigger than a small number will force domain names to be interpretet as relative. -R retries INT_MIN, INT_MAX - 1 Specifically documented to accept negative numbers. -W wait 0, INT_MAX One could interpret the documentation as meaning that it accepts negative numbers but that failes later on with an error message from the timer code.. with deraadt, OK kn, input & OK tedu
Diffstat (limited to 'usr.sbin/bind/bin/dig')
-rw-r--r--usr.sbin/bind/bin/dig/host.c24
1 files changed, 15 insertions, 9 deletions
diff --git a/usr.sbin/bind/bin/dig/host.c b/usr.sbin/bind/bin/dig/host.c
index 227bf11d168..085b0f32366 100644
--- a/usr.sbin/bind/bin/dig/host.c
+++ b/usr.sbin/bind/bin/dig/host.c
@@ -17,20 +17,18 @@
/*! \file */
#include <sys/cdefs.h>
-#include <stdlib.h>
-#include <unistd.h>
+#include <err.h>
#include <limits.h>
-
#include <locale.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
#include <isc/app.h>
#include <isc/netaddr.h>
-
-#include <string.h>
#include <isc/util.h>
#include <isc/task.h>
-
#include <dns/byaddr.h>
#include <dns/fixedname.h>
#include <dns/message.h>
@@ -628,6 +626,7 @@ parse_args(int argc, char **argv) {
dns_rdatatype_t rdtype;
dns_rdataclass_t rdclass;
uint32_t serial = 0;
+ const char *errstr;
lookup = make_empty_lookup();
@@ -727,12 +726,17 @@ parse_args(int argc, char **argv) {
timeout = INT_MAX;
break;
case 'W':
- timeout = atoi(optarg);
+ timeout = strtonum(optarg, 0, INT_MAX, &errstr);
+ if (errstr != NULL)
+ errx(1, "timeout is %s: %s", errstr, optarg);
if (timeout < 1)
timeout = 1;
break;
case 'R':
- tries = atoi(optarg) + 1;
+ tries = strtonum(optarg, INT_MIN, INT_MAX - 1, &errstr);
+ if (errstr != NULL)
+ errx(1, "retries is %s: %s", errstr, optarg);
+ tries++;
if (tries < 2)
tries = 2;
break;
@@ -752,7 +756,9 @@ parse_args(int argc, char **argv) {
break;
case 'N':
debug("setting NDOTS to %s", optarg);
- ndots = atoi(optarg);
+ ndots = strtonum(optarg, 0, INT_MAX, &errstr);
+ if (errstr != NULL)
+ errx(1, "ndots is %s: %s", errstr, optarg);
break;
case 'D':
/* Handled by pre_parse_args(). */