diff options
Diffstat (limited to 'usr.sbin/bind/lib/isc/parseint.c')
| -rw-r--r-- | usr.sbin/bind/lib/isc/parseint.c | 17 |
1 files changed, 12 insertions, 5 deletions
diff --git a/usr.sbin/bind/lib/isc/parseint.c b/usr.sbin/bind/lib/isc/parseint.c index 8cc269f8482..d6635802d6a 100644 --- a/usr.sbin/bind/lib/isc/parseint.c +++ b/usr.sbin/bind/lib/isc/parseint.c @@ -1,8 +1,8 @@ /* - * Copyright (C) 2004, 2005 Internet Systems Consortium, Inc. ("ISC") + * Copyright (C) 2004, 2005, 2007, 2012 Internet Systems Consortium, Inc. ("ISC") * Copyright (C) 2001-2003 Internet Software Consortium. * - * Permission to use, copy, modify, and distribute this software for any + * Permission to use, copy, modify, and/or distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies. * @@ -15,7 +15,7 @@ * PERFORMANCE OF THIS SOFTWARE. */ -/* $ISC: parseint.c,v 1.4.18.2 2005/04/29 00:16:48 marka Exp $ */ +/* $Id: parseint.c,v 1.2 2019/12/16 16:16:26 deraadt Exp $ */ /*! \file */ @@ -32,6 +32,7 @@ isc_result_t isc_parse_uint32(isc_uint32_t *uip, const char *string, int base) { unsigned long n; + isc_uint32_t r; char *e; if (! isalnum((unsigned char)(string[0]))) return (ISC_R_BADNUMBER); @@ -39,9 +40,15 @@ isc_parse_uint32(isc_uint32_t *uip, const char *string, int base) { n = strtoul(string, &e, base); if (*e != '\0') return (ISC_R_BADNUMBER); - if (n == ULONG_MAX && errno == ERANGE) + /* + * Where long is 64 bits we need to convert to 32 bits then test for + * equality. This is a no-op on 32 bit machines and a good compiler + * will optimise it away. + */ + r = (isc_uint32_t)n; + if ((n == ULONG_MAX && errno == ERANGE) || (n != (unsigned long)r)) return (ISC_R_RANGE); - *uip = n; + *uip = r; return (ISC_R_SUCCESS); } |
