mirror of
https://gitlab.isc.org/isc-projects/bind9
synced 2025-09-01 15:05:23 +00:00
1151. [bug] nslookup failed to check that the arguments to
the port, timeout, and retry options were valid integers and in range. [RT #2099] 1150. [bug] named incorrectly accepted TTL values containing plus or minus signs, such as 1d+1h-1s. 1149. [func] New function isc_parse_uint32().
This commit is contained in:
10
CHANGES
10
CHANGES
@@ -1,3 +1,13 @@
|
||||
1151. [bug] nslookup failed to check that the arguments to
|
||||
the port, timeout, and retry options were
|
||||
valid integers and in range. [RT #2099]
|
||||
|
||||
1150. [bug] named incorrectly accepted TTL values
|
||||
containing plus or minus signs, such as
|
||||
1d+1h-1s.
|
||||
|
||||
1149. [func] New function isc_parse_uint32().
|
||||
|
||||
1148. [func] 'rndc-confgen -a' provide positive feedback.
|
||||
|
||||
1147. [func] Set IPV6_V6ONLY on IPv6 sockets if supported by
|
||||
|
@@ -15,7 +15,7 @@
|
||||
* WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
/* $Id: dig.c,v 1.173 2001/11/28 02:46:21 gson Exp $ */
|
||||
/* $Id: dig.c,v 1.174 2001/11/30 01:02:05 gson Exp $ */
|
||||
|
||||
#include <config.h>
|
||||
#include <stdlib.h>
|
||||
@@ -24,6 +24,7 @@
|
||||
|
||||
#include <isc/app.h>
|
||||
#include <isc/netaddr.h>
|
||||
#include <isc/parseint.h>
|
||||
#include <isc/print.h>
|
||||
#include <isc/string.h>
|
||||
#include <isc/util.h>
|
||||
@@ -598,14 +599,14 @@ reorder_args(int argc, char *argv[]) {
|
||||
|
||||
static isc_uint32_t
|
||||
parse_uint(char *arg, const char *desc, isc_uint32_t max) {
|
||||
char *endp;
|
||||
isc_result_t result;
|
||||
isc_uint32_t tmp;
|
||||
|
||||
tmp = strtoul(arg, &endp, 10);
|
||||
if (*endp != '\0')
|
||||
fatal("%s '%s' must be numeric", desc, arg);
|
||||
if (tmp > max)
|
||||
fatal("%s '%s' out of range", desc, arg);
|
||||
result = isc_parse_uint32(&tmp, arg, 10);
|
||||
if (result == ISC_R_SUCCESS && tmp > max)
|
||||
result = ISC_R_RANGE;
|
||||
if (result != ISC_R_SUCCESS)
|
||||
fatal("%s '%s': %s", desc, arg, isc_result_totext(result));
|
||||
return (tmp);
|
||||
}
|
||||
|
||||
|
@@ -15,7 +15,7 @@
|
||||
* WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
/* $Id: nslookup.c,v 1.93 2001/11/22 01:59:02 gson Exp $ */
|
||||
/* $Id: nslookup.c,v 1.94 2001/11/30 01:02:06 gson Exp $ */
|
||||
|
||||
#include <config.h>
|
||||
|
||||
@@ -25,6 +25,7 @@
|
||||
#include <isc/buffer.h>
|
||||
#include <isc/commandline.h>
|
||||
#include <isc/event.h>
|
||||
#include <isc/parseint.h>
|
||||
#include <isc/string.h>
|
||||
#include <isc/timer.h>
|
||||
#include <isc/util.h>
|
||||
@@ -518,6 +519,44 @@ safecpy(char *dest, char *src, int size) {
|
||||
dest[size-1] = 0;
|
||||
}
|
||||
|
||||
static isc_result_t
|
||||
parse_uint(isc_uint32_t *uip, const char *value, isc_uint32_t max, const char *desc) {
|
||||
isc_uint32_t n;
|
||||
isc_result_t result = isc_parse_uint32(&n, value, 10);
|
||||
if (result == ISC_R_SUCCESS && n > max)
|
||||
result = ISC_R_RANGE;
|
||||
if (result != ISC_R_SUCCESS) {
|
||||
printf("invalid %s '%s': %s\n", desc,
|
||||
value, isc_result_totext(result));
|
||||
return result;
|
||||
}
|
||||
*uip = n;
|
||||
return (ISC_R_SUCCESS);
|
||||
}
|
||||
|
||||
static void
|
||||
set_port(const char *value) {
|
||||
isc_uint32_t n;
|
||||
isc_result_t result = parse_uint(&n, value, 65535, "port");
|
||||
if (result == ISC_R_SUCCESS)
|
||||
port = n;
|
||||
}
|
||||
|
||||
static void
|
||||
set_timeout(const char *value) {
|
||||
isc_uint32_t n;
|
||||
isc_result_t result = parse_uint(&n, value, UINT_MAX, "timeout");
|
||||
if (result == ISC_R_SUCCESS)
|
||||
timeout = n;
|
||||
}
|
||||
|
||||
static void
|
||||
set_tries(const char *value) {
|
||||
isc_uint32_t n;
|
||||
isc_result_t result = parse_uint(&n, value, INT_MAX, "tries");
|
||||
if (result == ISC_R_SUCCESS)
|
||||
tries = n;
|
||||
}
|
||||
|
||||
static void
|
||||
setoption(char *opt) {
|
||||
@@ -553,21 +592,21 @@ setoption(char *opt) {
|
||||
set_search_domain(domainopt);
|
||||
usesearch = ISC_TRUE;
|
||||
} else if (strncasecmp(opt, "port=", 5) == 0) {
|
||||
port = atoi(&opt[5]);
|
||||
set_port(&opt[5]);
|
||||
} else if (strncasecmp(opt, "po=", 3) == 0) {
|
||||
port = atoi(&opt[3]);
|
||||
set_port(&opt[3]);
|
||||
} else if (strncasecmp(opt, "timeout=", 8) == 0) {
|
||||
timeout = atoi(&opt[8]);
|
||||
set_timeout(&opt[8]);
|
||||
} else if (strncasecmp(opt, "t=", 2) == 0) {
|
||||
timeout = atoi(&opt[2]);
|
||||
set_timeout(&opt[2]);
|
||||
} else if (strncasecmp(opt, "rec", 3) == 0) {
|
||||
recurse = ISC_TRUE;
|
||||
} else if (strncasecmp(opt, "norec", 5) == 0) {
|
||||
recurse = ISC_FALSE;
|
||||
} else if (strncasecmp(opt, "retry=", 6) == 0) {
|
||||
tries = atoi(&opt[6]);
|
||||
set_tries(&opt[6]);
|
||||
} else if (strncasecmp(opt, "ret=", 4) == 0) {
|
||||
tries = atoi(&opt[4]);
|
||||
set_tries(&opt[4]);
|
||||
} else if (strncasecmp(opt, "def", 3) == 0) {
|
||||
usesearch = ISC_TRUE;
|
||||
} else if (strncasecmp(opt, "nodef", 5) == 0) {
|
||||
|
@@ -15,7 +15,7 @@
|
||||
* WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
/* $Id: nsupdate.c,v 1.114 2001/11/22 00:59:18 gson Exp $ */
|
||||
/* $Id: nsupdate.c,v 1.115 2001/11/30 01:02:08 gson Exp $ */
|
||||
|
||||
#include <config.h>
|
||||
|
||||
@@ -33,6 +33,7 @@
|
||||
#include <isc/event.h>
|
||||
#include <isc/lex.h>
|
||||
#include <isc/mem.h>
|
||||
#include <isc/parseint.h>
|
||||
#include <isc/region.h>
|
||||
#include <isc/sockaddr.h>
|
||||
#include <isc/socket.h>
|
||||
@@ -1058,7 +1059,7 @@ static isc_uint16_t
|
||||
update_addordelete(char *cmdline, isc_boolean_t isdelete) {
|
||||
isc_result_t result;
|
||||
dns_name_t *name = NULL;
|
||||
unsigned long ttl;
|
||||
isc_uint32_t ttl;
|
||||
char *word;
|
||||
dns_rdataclass_t rdataclass;
|
||||
dns_rdatatype_t rdatatype;
|
||||
@@ -1066,7 +1067,6 @@ update_addordelete(char *cmdline, isc_boolean_t isdelete) {
|
||||
dns_rdatalist_t *rdatalist = NULL;
|
||||
dns_rdataset_t *rdataset = NULL;
|
||||
isc_textregion_t region;
|
||||
char *endp;
|
||||
isc_uint16_t retval;
|
||||
|
||||
ddebug("update_addordelete()");
|
||||
@@ -1104,13 +1104,14 @@ update_addordelete(char *cmdline, isc_boolean_t isdelete) {
|
||||
goto doneparsing;
|
||||
}
|
||||
}
|
||||
ttl = strtoul(word, &endp, 10);
|
||||
if (!isdigit((unsigned char)*word) || *endp != '\0') {
|
||||
result = isc_parse_uint32(&ttl, word, 10);
|
||||
if (result != ISC_R_SUCCESS) {
|
||||
if (isdelete) {
|
||||
ttl = 0;
|
||||
goto parseclass;
|
||||
} else {
|
||||
fprintf(stderr, "ttl '%s' is not legal\n", word);
|
||||
fprintf(stderr, "ttl '%s': %s\n", word,
|
||||
isc_result_totext(result));
|
||||
goto failure;
|
||||
}
|
||||
}
|
||||
|
@@ -15,7 +15,7 @@
|
||||
* WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
/* $Id: rdata.c,v 1.155 2001/11/26 23:37:24 gson Exp $ */
|
||||
/* $Id: rdata.c,v 1.156 2001/11/30 01:02:09 gson Exp $ */
|
||||
|
||||
#include <config.h>
|
||||
#include <ctype.h>
|
||||
@@ -24,6 +24,7 @@
|
||||
#include <isc/hex.h>
|
||||
#include <isc/lex.h>
|
||||
#include <isc/mem.h>
|
||||
#include <isc/parseint.h>
|
||||
#include <isc/print.h>
|
||||
#include <isc/string.h>
|
||||
#include <isc/util.h>
|
||||
@@ -961,34 +962,51 @@ dns_rdatatype_attributes(dns_rdatatype_t type)
|
||||
|
||||
#define NUMBERSIZE sizeof("037777777777") /* 2^32-1 octal + NUL */
|
||||
|
||||
/*
|
||||
* If 'source' contains a decimal number no larger than 'max',
|
||||
* store it at '*value' and return ISC_R_SUCCESS. If out of
|
||||
* range return ISC_R_RANGE; if not a number, return
|
||||
* ISC_R_BADNUMBER.
|
||||
*/
|
||||
static isc_result_t
|
||||
dns_mnemonic_fromtext(unsigned int *valuep, isc_textregion_t *source,
|
||||
struct tbl *table, unsigned int max)
|
||||
maybe_numeric(unsigned int *valuep, isc_textregion_t *source,
|
||||
unsigned int max)
|
||||
{
|
||||
int i;
|
||||
|
||||
if (isdigit(source->base[0] & 0xff) &&
|
||||
source->length <= NUMBERSIZE - 1) {
|
||||
unsigned int n;
|
||||
char *e;
|
||||
isc_result_t result;
|
||||
isc_uint32_t n;
|
||||
char buffer[NUMBERSIZE];
|
||||
|
||||
if (! isdigit(source->base[0] & 0xff) ||
|
||||
source->length > NUMBERSIZE - 1)
|
||||
return (ISC_R_BADNUMBER);
|
||||
|
||||
/*
|
||||
* We have a potential number. Try to parse it with strtoul().
|
||||
* strtoul() requires null termination, so we must make
|
||||
* a copy.
|
||||
* We have a potential number. Try to parse it with
|
||||
* isc_parse_uint32(). isc_parse_uint32() requires
|
||||
* null termination, so we must make a copy.
|
||||
*/
|
||||
strncpy(buffer, source->base, NUMBERSIZE);
|
||||
INSIST(buffer[source->length] == '\0');
|
||||
|
||||
n = strtoul(buffer, &e, 10);
|
||||
if (*e == 0) {
|
||||
result = isc_parse_uint32(&n, buffer, 10);
|
||||
if (result != ISC_R_SUCCESS)
|
||||
return (result);
|
||||
if (n > max)
|
||||
return (ISC_R_RANGE);
|
||||
*valuep = n;
|
||||
return (ISC_R_SUCCESS);
|
||||
}
|
||||
/* It was not a number after all; fall through. */
|
||||
}
|
||||
}
|
||||
|
||||
static isc_result_t
|
||||
dns_mnemonic_fromtext(unsigned int *valuep, isc_textregion_t *source,
|
||||
struct tbl *table, unsigned int max)
|
||||
{
|
||||
isc_result_t result;
|
||||
int i;
|
||||
|
||||
result = maybe_numeric(valuep, source, max);
|
||||
if (result != ISC_R_BADNUMBER)
|
||||
return (result);
|
||||
|
||||
for (i = 0; table[i].name != NULL; i++) {
|
||||
unsigned int n;
|
||||
@@ -1264,31 +1282,17 @@ dns_secproto_totext(dns_secproto_t secproto, isc_buffer_t *target) {
|
||||
isc_result_t
|
||||
dns_keyflags_fromtext(dns_keyflags_t *flagsp, isc_textregion_t *source)
|
||||
{
|
||||
isc_result_t result;
|
||||
char *text, *end;
|
||||
unsigned int value, mask;
|
||||
|
||||
if (isdigit(source->base[0] & 0xff) &&
|
||||
source->length <= NUMBERSIZE - 1) {
|
||||
unsigned int n;
|
||||
char *e;
|
||||
char buffer[NUMBERSIZE];
|
||||
/*
|
||||
* We have a potential number. Try to parse it with strtoul().
|
||||
* strtoul() requires null termination, so we must make
|
||||
* a copy.
|
||||
*/
|
||||
strncpy(buffer, source->base, NUMBERSIZE);
|
||||
INSIST(buffer[source->length] == '\0');
|
||||
|
||||
n = strtoul(buffer, &e, 0); /* Allow hex/octal. */
|
||||
if (*e == 0) {
|
||||
if (n > 0xffff)
|
||||
return (ISC_R_RANGE);
|
||||
*flagsp = n;
|
||||
result = maybe_numeric(&value, source, 0xffff);
|
||||
if (result == ISC_R_SUCCESS) {
|
||||
*flagsp = value;
|
||||
return (ISC_R_SUCCESS);
|
||||
}
|
||||
/* It was not a number after all; fall through. */
|
||||
}
|
||||
if (result != ISC_R_BADNUMBER)
|
||||
return (result);
|
||||
|
||||
text = source->base;
|
||||
end = source->base + source->length;
|
||||
|
@@ -15,7 +15,7 @@
|
||||
* WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
/* $Id: ttl.c,v 1.23 2001/11/26 23:51:21 gson Exp $ */
|
||||
/* $Id: ttl.c,v 1.24 2001/11/30 01:02:10 gson Exp $ */
|
||||
|
||||
#include <config.h>
|
||||
|
||||
@@ -25,6 +25,7 @@
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <isc/buffer.h>
|
||||
#include <isc/parseint.h>
|
||||
#include <isc/print.h>
|
||||
#include <isc/region.h>
|
||||
#include <isc/string.h>
|
||||
@@ -146,9 +147,10 @@ dns_ttl_fromtext(isc_textregion_t *source, isc_uint32_t *ttl) {
|
||||
static isc_result_t
|
||||
bind_ttl(isc_textregion_t *source, isc_uint32_t *ttl) {
|
||||
isc_uint32_t tmp = 0;
|
||||
unsigned long n;
|
||||
char *e, *s;
|
||||
isc_uint32_t n;
|
||||
char *s;
|
||||
char buf[64];
|
||||
char nbuf[64]; /* Number buffer */
|
||||
|
||||
/*
|
||||
* Copy the buffer as it may not be NULL terminated.
|
||||
@@ -161,49 +163,52 @@ bind_ttl(isc_textregion_t *source, isc_uint32_t *ttl) {
|
||||
s = buf;
|
||||
|
||||
do {
|
||||
errno = 0;
|
||||
n = strtoul(s, &e, 10);
|
||||
if (s == e)
|
||||
isc_result_t result;
|
||||
|
||||
char *np = nbuf;
|
||||
while (*s != '\0' && isdigit((unsigned char)*s))
|
||||
*np++ = *s++;
|
||||
*np++ = '\0';
|
||||
INSIST(np - nbuf <= (int)sizeof(nbuf));
|
||||
result = isc_parse_uint32(&n, nbuf, 10);
|
||||
if (result != ISC_R_SUCCESS)
|
||||
return (DNS_R_SYNTAX);
|
||||
if (n == UINT_MAX && errno == ERANGE)
|
||||
return (DNS_R_SYNTAX);
|
||||
switch (*e) {
|
||||
switch (*s) {
|
||||
case 'w':
|
||||
case 'W':
|
||||
tmp += n * 7 * 24 * 3600;
|
||||
s = e + 1;
|
||||
s++;
|
||||
break;
|
||||
case 'd':
|
||||
case 'D':
|
||||
tmp += n * 24 * 3600;
|
||||
s = e + 1;
|
||||
s++;
|
||||
break;
|
||||
case 'h':
|
||||
case 'H':
|
||||
tmp += n * 3600;
|
||||
s = e + 1;
|
||||
s++;
|
||||
break;
|
||||
case 'm':
|
||||
case 'M':
|
||||
tmp += n * 60;
|
||||
s = e + 1;
|
||||
s++;
|
||||
break;
|
||||
case 's':
|
||||
case 'S':
|
||||
tmp += n;
|
||||
s = e + 1;
|
||||
s++;
|
||||
break;
|
||||
case '\0':
|
||||
/* Plain number? */
|
||||
if (tmp != 0)
|
||||
return (DNS_R_SYNTAX);
|
||||
tmp = n;
|
||||
s = e;
|
||||
break;
|
||||
default:
|
||||
return (DNS_R_SYNTAX);
|
||||
}
|
||||
} while (*s != 0);
|
||||
} while (*s != '\0');
|
||||
*ttl = tmp;
|
||||
return (ISC_R_SUCCESS);
|
||||
}
|
||||
|
@@ -13,7 +13,7 @@
|
||||
# NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
|
||||
# WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
|
||||
# $Id: Makefile.in,v 1.72 2001/08/30 04:49:36 marka Exp $
|
||||
# $Id: Makefile.in,v 1.73 2001/11/30 01:02:12 gson Exp $
|
||||
|
||||
srcdir = @srcdir@
|
||||
VPATH = @srcdir@
|
||||
@@ -55,7 +55,7 @@ OBJS = @ISC_EXTRA_OBJS@ \
|
||||
heap.@O@ hex.@O@ hmacmd5.@O@ \
|
||||
lex.@O@ lfsr.@O@ lib.@O@ log.@O@ \
|
||||
md5.@O@ mem.@O@ mutexblock.@O@ netaddr.@O@ ondestroy.@O@ \
|
||||
quota.@O@ random.@O@ \
|
||||
parseint.@O@ quota.@O@ random.@O@ \
|
||||
ratelimiter.@O@ result.@O@ rwlock.@O@ \
|
||||
serial.@O@ sha1.@O@ sockaddr.@O@ string.@O@ symtab.@O@ \
|
||||
task.@O@ taskpool.@O@ timer.@O@ version.@O@ \
|
||||
@@ -68,7 +68,7 @@ SRCS = @ISC_EXTRA_SRCS@ \
|
||||
heap.c hex.c hmacmd5.c \
|
||||
lex.c lfsr.c lib.c log.c \
|
||||
md5.c mem.c mutexblock.c netaddr.c ondestroy.c \
|
||||
quota.c random.c \
|
||||
parseint.c quota.c random.c \
|
||||
ratelimiter.c result.c rwlock.c \
|
||||
serial.c sha1.c sockaddr.c string.c symtab.c \
|
||||
task.c taskpool.c timer.c version.c
|
||||
|
@@ -13,7 +13,7 @@
|
||||
# NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
|
||||
# WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
|
||||
# $Id: Makefile.in,v 1.51 2001/10/16 23:20:56 gson Exp $
|
||||
# $Id: Makefile.in,v 1.52 2001/11/30 01:02:16 gson Exp $
|
||||
|
||||
srcdir = @srcdir@
|
||||
VPATH = @srcdir@
|
||||
@@ -32,7 +32,7 @@ HEADERS = app.h assertions.h base64.h bitstring.h boolean.h buffer.h \
|
||||
file.h formatcheck.h fsaccess.h heap.h hex.h hmacmd5.h \
|
||||
interfaceiter.h @ISC_IPV6_H@ lang.h lex.h \
|
||||
lfsr.h lib.h list.h log.h magic.h md5.h mem.h msgcat.h msgs.h \
|
||||
mutexblock.h netaddr.h ondestroy.h os.h \
|
||||
mutexblock.h netaddr.h ondestroy.h os.h parseint.h \
|
||||
print.h quota.h random.h ratelimiter.h \
|
||||
refcount.h region.h resource.h \
|
||||
result.h resultclass.h rwlock.h serial.h sha1.h sockaddr.h \
|
||||
|
57
lib/isc/include/isc/parseint.h
Normal file
57
lib/isc/include/isc/parseint.h
Normal file
@@ -0,0 +1,57 @@
|
||||
/*
|
||||
* Copyright (C) 2001 Internet Software Consortium.
|
||||
*
|
||||
* Permission to use, copy, modify, and 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.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM
|
||||
* DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL
|
||||
* INTERNET SOFTWARE CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT,
|
||||
* INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING
|
||||
* FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
|
||||
* NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
|
||||
* WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
/* $Id: parseint.h,v 1.1 2001/11/30 01:02:17 gson Exp $ */
|
||||
|
||||
#ifndef ISC_PARSEINT_H
|
||||
#define ISC_PARSEINT_H 1
|
||||
|
||||
#include <isc/lang.h>
|
||||
#include <isc/types.h>
|
||||
|
||||
/*
|
||||
* Parse integers, in a saner way than atoi() or strtoul() do.
|
||||
*/
|
||||
|
||||
/***
|
||||
*** Functions
|
||||
***/
|
||||
|
||||
ISC_LANG_BEGINDECLS
|
||||
|
||||
isc_result_t
|
||||
isc_parse_uint32(isc_uint32_t *uip, const char *string, int base);
|
||||
/*
|
||||
* Parse the null-terminated string 'string' containing a base 'base'
|
||||
* integer, storing the result in '*uip'. The base is interpreted
|
||||
* as in strtoul(). Unlike strtoul(), leading whitespace, minus or
|
||||
* plus signs are not accepted, and all errors (including overflow)
|
||||
* are reported uniformly through the return value.
|
||||
*
|
||||
* Requires:
|
||||
* 'string' points to a null-terminated string
|
||||
* 0 <= 'base' <= 36
|
||||
*
|
||||
* Returns:
|
||||
* ISC_R_SUCCESS
|
||||
* ISC_R_BADNUMBER The string is not numeric (in the given base)
|
||||
* ISC_R_RANGE The number is not representable as an isc_uint32_t
|
||||
*/
|
||||
|
||||
ISC_LANG_ENDDECLS
|
||||
|
||||
#endif /* ISC_PARSEINT_H */
|
@@ -15,7 +15,7 @@
|
||||
* WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
/* $Id: result.h,v 1.58 2001/10/22 07:09:24 marka Exp $ */
|
||||
/* $Id: result.h,v 1.59 2001/11/30 01:02:17 gson Exp $ */
|
||||
|
||||
#ifndef ISC_RESULT_H
|
||||
#define ISC_RESULT_H 1
|
||||
@@ -79,11 +79,12 @@
|
||||
#define ISC_R_INPROGRESS 53 /* operation in progress */
|
||||
#define ISC_R_CONNECTIONRESET 54 /* connection reset */
|
||||
#define ISC_R_SOFTQUOTA 55 /* soft quota reached */
|
||||
#define ISC_R_BADNUMBER 56 /* not a valid number */
|
||||
|
||||
/*
|
||||
* Not a result code: the number of results.
|
||||
*/
|
||||
#define ISC_R_NRESULTS 56
|
||||
#define ISC_R_NRESULTS 57
|
||||
|
||||
ISC_LANG_BEGINDECLS
|
||||
|
||||
|
@@ -15,7 +15,7 @@
|
||||
* WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
/* $Id: lex.c,v 1.69 2001/11/27 01:56:02 gson Exp $ */
|
||||
/* $Id: lex.c,v 1.70 2001/11/30 01:02:13 gson Exp $ */
|
||||
|
||||
#include <config.h>
|
||||
|
||||
@@ -28,6 +28,7 @@
|
||||
#include <isc/lex.h>
|
||||
#include <isc/mem.h>
|
||||
#include <isc/msgs.h>
|
||||
#include <isc/parseint.h>
|
||||
#include <isc/stdio.h>
|
||||
#include <isc/string.h>
|
||||
#include <isc/util.h>
|
||||
@@ -361,9 +362,8 @@ isc_lex_gettoken(isc_lex_t *lex, unsigned int options, isc_token_t *tokenp) {
|
||||
FILE *stream;
|
||||
char *curr, *prev;
|
||||
size_t remaining;
|
||||
unsigned long as_ulong;
|
||||
isc_uint32_t as_ulong;
|
||||
unsigned int saved_options;
|
||||
char *e;
|
||||
isc_result_t result;
|
||||
|
||||
/*
|
||||
@@ -588,17 +588,16 @@ isc_lex_gettoken(isc_lex_t *lex, unsigned int options, isc_token_t *tokenp) {
|
||||
else
|
||||
base = 10;
|
||||
pushback(source, c);
|
||||
as_ulong = strtoul(lex->data, &e, base);
|
||||
if (as_ulong == ULONG_MAX &&
|
||||
errno == ERANGE) {
|
||||
result = ISC_R_RANGE;
|
||||
goto done;
|
||||
} else if (*e == 0) {
|
||||
|
||||
result = isc_parse_uint32(&as_ulong,
|
||||
lex->data,
|
||||
base);
|
||||
if (result == ISC_R_SUCCESS) {
|
||||
tokenp->type =
|
||||
isc_tokentype_number;
|
||||
tokenp->value.as_ulong =
|
||||
as_ulong;
|
||||
} else {
|
||||
} else if (result == ISC_R_BADNUMBER) {
|
||||
isc_tokenvalue_t *v;
|
||||
|
||||
tokenp->type =
|
||||
@@ -609,7 +608,8 @@ isc_lex_gettoken(isc_lex_t *lex, unsigned int options, isc_token_t *tokenp) {
|
||||
v->as_textregion.length =
|
||||
lex->max_token -
|
||||
remaining;
|
||||
}
|
||||
} else
|
||||
goto done;
|
||||
done = ISC_TRUE;
|
||||
continue;
|
||||
} else if (!(options & ISC_LEXOPT_CNUMBER) ||
|
||||
|
44
lib/isc/parseint.c
Normal file
44
lib/isc/parseint.c
Normal file
@@ -0,0 +1,44 @@
|
||||
/*
|
||||
* Copyright (C) 2001 Internet Software Consortium.
|
||||
*
|
||||
* Permission to use, copy, modify, and 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.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM
|
||||
* DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL
|
||||
* INTERNET SOFTWARE CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT,
|
||||
* INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING
|
||||
* FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
|
||||
* NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
|
||||
* WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
/* $Id: parseint.c,v 1.1 2001/11/30 01:02:14 gson Exp $ */
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include <ctype.h>
|
||||
#include <errno.h>
|
||||
#include <limits.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <isc/parseint.h>
|
||||
#include <isc/result.h>
|
||||
|
||||
isc_result_t
|
||||
isc_parse_uint32(isc_uint32_t *uip, const char *string, int base) {
|
||||
unsigned long n;
|
||||
char *e;
|
||||
if (! isalnum((unsigned char)(string[0])))
|
||||
return (ISC_R_BADNUMBER);
|
||||
errno = 0;
|
||||
n = strtoul(string, &e, base);
|
||||
if (*e != '\0')
|
||||
return (ISC_R_BADNUMBER);
|
||||
if (n == ULONG_MAX && errno == ERANGE)
|
||||
return (ISC_R_RANGE);
|
||||
*uip = n;
|
||||
return (ISC_R_SUCCESS);
|
||||
}
|
@@ -15,7 +15,7 @@
|
||||
* WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
/* $Id: result.c,v 1.58 2001/11/27 01:56:05 gson Exp $ */
|
||||
/* $Id: result.c,v 1.59 2001/11/30 01:02:14 gson Exp $ */
|
||||
|
||||
#include <config.h>
|
||||
|
||||
@@ -93,7 +93,8 @@ static const char *text[ISC_R_NRESULTS] = {
|
||||
"unbalanced quotes", /* 52 */
|
||||
"operation in progress", /* 53 */
|
||||
"connection reset", /* 54 */
|
||||
"soft quota reached" /* 55 */
|
||||
"soft quota reached", /* 55 */
|
||||
"not a valid number" /* 56 */
|
||||
};
|
||||
|
||||
#define ISC_RESULT_RESULTSET 2
|
||||
|
@@ -1847,6 +1847,7 @@
|
||||
./lib/isc/include/isc/netaddr.h C 1998,1999,2000,2001
|
||||
./lib/isc/include/isc/ondestroy.h C 2000,2001
|
||||
./lib/isc/include/isc/os.h C 2000,2001
|
||||
./lib/isc/include/isc/parseint.h C 2001
|
||||
./lib/isc/include/isc/platform.h.in C 1999,2000,2001
|
||||
./lib/isc/include/isc/print.h C 1999,2000,2001
|
||||
./lib/isc/include/isc/quota.h C 2000,2001
|
||||
@@ -1899,6 +1900,7 @@
|
||||
./lib/isc/nothreads/mutex.c C 2000,2001
|
||||
./lib/isc/nothreads/thread.c C 2000,2001
|
||||
./lib/isc/ondestroy.c C 2000,2001
|
||||
./lib/isc/parseint.c C 2001
|
||||
./lib/isc/print.c C 1999,2000,2001
|
||||
./lib/isc/pthreads/.cvsignore X 1999,2000,2001
|
||||
./lib/isc/pthreads/Makefile.in MAKE 1998,1999,2000,2001
|
||||
|
Reference in New Issue
Block a user