summaryrefslogtreecommitdiffstats
path: root/lib/libc/net/res_init.c
diff options
context:
space:
mode:
authormillert <millert@openbsd.org>1999-09-03 16:23:18 +0000
committermillert <millert@openbsd.org>1999-09-03 16:23:18 +0000
commitcd9486a8767de6c1e4e5b2c6c4ee58666074e221 (patch)
treec03cb5163270691a14cfa409cd48605dd1204db9 /lib/libc/net/res_init.c
parentinet_ntoa4 should manage 4-calls, not just 2 (diff)
downloadwireguard-openbsd-cd9486a8767de6c1e4e5b2c6c4ee58666074e221.tar.xz
wireguard-openbsd-cd9486a8767de6c1e4e5b2c6c4ee58666074e221.zip
Use strtol() and strtoul() instead of atoi(). This allows us to catch
errors reasonably and deal correctly with unsigned quantities.
Diffstat (limited to 'lib/libc/net/res_init.c')
-rw-r--r--lib/libc/net/res_init.c25
1 files changed, 15 insertions, 10 deletions
diff --git a/lib/libc/net/res_init.c b/lib/libc/net/res_init.c
index df176b7fa1d..2e8023ad310 100644
--- a/lib/libc/net/res_init.c
+++ b/lib/libc/net/res_init.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: res_init.c,v 1.16 1998/03/16 05:07:01 millert Exp $ */
+/* $OpenBSD: res_init.c,v 1.17 1999/09/03 16:23:19 millert Exp $ */
/*
* ++Copyright++ 1985, 1989, 1993
@@ -60,7 +60,7 @@
static char sccsid[] = "@(#)res_init.c 8.1 (Berkeley) 6/7/93";
static char rcsid[] = "$From: res_init.c,v 8.7 1996/09/28 06:51:07 vixie Exp $";
#else
-static char rcsid[] = "$OpenBSD: res_init.c,v 1.16 1998/03/16 05:07:01 millert Exp $";
+static char rcsid[] = "$OpenBSD: res_init.c,v 1.17 1999/09/03 16:23:19 millert Exp $";
#endif
#endif /* LIBC_SCCS and not lint */
@@ -459,7 +459,8 @@ res_setoptions(options, source)
char *options, *source;
{
char *cp = options;
- int i;
+ char *endp;
+ long l;
#ifdef DEBUG
if (_res.options & RES_DEBUG)
@@ -472,15 +473,19 @@ res_setoptions(options, source)
cp++;
/* search for and process individual options */
if (!strncmp(cp, "ndots:", sizeof("ndots:") - 1)) {
- i = atoi(cp + sizeof("ndots:") - 1);
- if (i <= RES_MAXNDOTS)
- _res.ndots = i;
- else
- _res.ndots = RES_MAXNDOTS;
+ char *p = cp + sizeof("ndots:") - 1;
+ l = strtol(p, &endp, 10);
+ if (l >= 0 && endp != p &&
+ (*endp = '\0' || issapce(*endp))) {
+ if (l <= RES_MAXNDOTS)
+ _res.ndots = l;
+ else
+ _res.ndots = RES_MAXNDOTS;
#ifdef DEBUG
- if (_res.options & RES_DEBUG)
- printf(";;\tndots=%d\n", _res.ndots);
+ if (_res.options & RES_DEBUG)
+ printf(";;\tndots=%d\n", _res.ndots);
#endif
+ }
} else if (!strncmp(cp, "debug", sizeof("debug") - 1)) {
#ifdef DEBUG
if (!(_res.options & RES_DEBUG)) {