2
0
mirror of https://gitlab.isc.org/isc-projects/bind9 synced 2025-09-02 07:35:26 +00:00

ensure proper range for argument to ctype functions

This commit is contained in:
David Lawrence
2000-05-09 22:22:25 +00:00
parent f855bad4a1
commit 47b26abe77
16 changed files with 535 additions and 521 deletions

View File

@@ -1,3 +1,5 @@
162. [bug] Ensure proper range for arguments to ctype.h functions.
161. [cleanup] error in yyparse prototype that only HPUX caught. 161. [cleanup] error in yyparse prototype that only HPUX caught.
160. [cleanup] getnet*() are not going to be implemented at this 160. [cleanup] getnet*() are not going to be implemented at this

View File

@@ -337,8 +337,10 @@ test_dns_db_zc_x(char *filename, isc_boolean_t cache,
++line; ++line;
/* skip comment lines */ /*
if ((isspace((int)*p)) || (*p == '#')) * Skip comment lines.
*/
if ((isspace((unsigned char)*p)) || (*p == '#'))
continue; continue;
cnt = t_bustline(p, tokens); cnt = t_bustline(p, tokens);

File diff suppressed because it is too large Load Diff

View File

@@ -435,7 +435,7 @@ test_dns_rbt_x(char *filename) {
/* /*
* Skip comment lines. * Skip comment lines.
*/ */
if ((isspace((int)*p)) || (*p == '#')) if ((isspace((unsigned char)*p)) || (*p == '#'))
continue; continue;
/* /*
@@ -919,8 +919,10 @@ test_dns_rbtnodechain_init(char *filename) {
++line; ++line;
/* skip comment lines */ /*
if ((isspace((int)*p)) || (*p == '#')) * Skip comment lines.
*/
if ((isspace((unsigned char)*p)) || (*p == '#'))
continue; continue;
cnt = t_bustline(p, Tokens); cnt = t_bustline(p, Tokens);
@@ -1082,7 +1084,7 @@ test_dns_rbtnodechain_first(char *filename) {
/* /*
* Skip comment lines. * Skip comment lines.
*/ */
if ((isspace((int)*p)) || (*p == '#')) if ((isspace((unsigned char)*p)) || (*p == '#'))
continue; continue;
cnt = t_bustline(p, Tokens); cnt = t_bustline(p, Tokens);
@@ -1247,7 +1249,7 @@ test_dns_rbtnodechain_last(char *filename) {
/* /*
* Skip comment lines. * Skip comment lines.
*/ */
if ((isspace((int)*p)) || (*p == '#')) if ((isspace((unsigned char)*p)) || (*p == '#'))
continue; continue;
cnt = t_bustline(p, Tokens); cnt = t_bustline(p, Tokens);
@@ -1428,7 +1430,7 @@ test_dns_rbtnodechain_next(char *filename) {
/* /*
* Skip comment lines. * Skip comment lines.
*/ */
if ((isspace((int)*p)) || (*p == '#')) if ((isspace((unsigned char)*p)) || (*p == '#'))
continue; continue;
cnt = t_bustline(p, Tokens); cnt = t_bustline(p, Tokens);
@@ -1607,7 +1609,7 @@ test_dns_rbtnodechain_prev(char *filename) {
/* /*
* Skip comment lines. * Skip comment lines.
*/ */
if ((isspace((int)*p)) || (*p == '#')) if ((isspace((unsigned char)*p)) || (*p == '#'))
continue; continue;
cnt = t_bustline(p, Tokens); cnt = t_bustline(p, Tokens);

View File

@@ -16,7 +16,7 @@
* SOFTWARE. * SOFTWARE.
*/ */
/* $Id: confparser.y,v 1.76 2000/05/09 16:49:50 brister Exp $ */ /* $Id: confparser.y,v 1.77 2000/05/09 22:22:15 tale Exp $ */
#include <config.h> #include <config.h>
@@ -5496,7 +5496,7 @@ unit_to_uint32(char *in, isc_uint32_t *out) {
for (; (c = *in) != '\0'; in++) { for (; (c = *in) != '\0'; in++) {
if (units_done) if (units_done)
return (ISC_FALSE); return (ISC_FALSE);
if (isdigit(c)) { if (isdigit((unsigned char)c)) {
result *= 10; result *= 10;
result += (c - '0'); result += (c - '0');
} else { } else {

View File

@@ -15,7 +15,7 @@
* SOFTWARE. * SOFTWARE.
*/ */
/* $Id: gen.c,v 1.45 2000/05/08 14:34:36 tale Exp $ */ /* $Id: gen.c,v 1.46 2000/05/09 22:22:11 tale Exp $ */
#include <config.h> #include <config.h>
@@ -34,31 +34,38 @@
#include "gen-unix.h" #include "gen-unix.h"
#endif #endif
#define FROMTEXTDECL "dns_rdataclass_t rdclass, dns_rdatatype_t type, isc_lex_t *lexer, dns_name_t *origin, isc_boolean_t downcase, isc_buffer_t *target" #define FROMTEXTDECL "dns_rdataclass_t rdclass, dns_rdatatype_t type, " \
"isc_lex_t *lexer, dns_name_t *origin, " \
"isc_boolean_t downcase, isc_buffer_t *target"
#define FROMTEXTARGS "rdclass, type, lexer, origin, downcase, target" #define FROMTEXTARGS "rdclass, type, lexer, origin, downcase, target"
#define FROMTEXTCLASS "rdclass" #define FROMTEXTCLASS "rdclass"
#define FROMTEXTTYPE "type" #define FROMTEXTTYPE "type"
#define FROMTEXTDEF "use_default = ISC_TRUE" #define FROMTEXTDEF "use_default = ISC_TRUE"
#define TOTEXTDECL "dns_rdata_t *rdata, dns_rdata_textctx_t *tctx, isc_buffer_t *target" #define TOTEXTDECL "dns_rdata_t *rdata, dns_rdata_textctx_t *tctx, " \
"isc_buffer_t *target"
#define TOTEXTARGS "rdata, tctx, target" #define TOTEXTARGS "rdata, tctx, target"
#define TOTEXTCLASS "rdata->rdclass" #define TOTEXTCLASS "rdata->rdclass"
#define TOTEXTTYPE "rdata->type" #define TOTEXTTYPE "rdata->type"
#define TOTEXTDEF "use_default = ISC_TRUE" #define TOTEXTDEF "use_default = ISC_TRUE"
#define FROMWIREDECL "dns_rdataclass_t rdclass, dns_rdatatype_t type, isc_buffer_t *source, dns_decompress_t *dctx, isc_boolean_t downcase, isc_buffer_t *target" #define FROMWIREDECL "dns_rdataclass_t rdclass, dns_rdatatype_t type, " \
"isc_buffer_t *source, dns_decompress_t *dctx, " \
"isc_boolean_t downcase, isc_buffer_t *target"
#define FROMWIREARGS "rdclass, type, source, dctx, downcase, target" #define FROMWIREARGS "rdclass, type, source, dctx, downcase, target"
#define FROMWIRECLASS "rdclass" #define FROMWIRECLASS "rdclass"
#define FROMWIRETYPE "type" #define FROMWIRETYPE "type"
#define FROMWIREDEF "use_default = ISC_TRUE" #define FROMWIREDEF "use_default = ISC_TRUE"
#define TOWIREDECL "dns_rdata_t *rdata, dns_compress_t *cctx, isc_buffer_t *target" #define TOWIREDECL "dns_rdata_t *rdata, dns_compress_t *cctx, " \
"isc_buffer_t *target"
#define TOWIREARGS "rdata, cctx, target" #define TOWIREARGS "rdata, cctx, target"
#define TOWIRECLASS "rdata->rdclass" #define TOWIRECLASS "rdata->rdclass"
#define TOWIRETYPE "rdata->type" #define TOWIRETYPE "rdata->type"
#define TOWIREDEF "use_default = ISC_TRUE" #define TOWIREDEF "use_default = ISC_TRUE"
#define FROMSTRUCTDECL "dns_rdataclass_t rdclass, dns_rdatatype_t type, void *source, isc_buffer_t *target" #define FROMSTRUCTDECL "dns_rdataclass_t rdclass, dns_rdatatype_t type, " \
"void *source, isc_buffer_t *target"
#define FROMSTRUCTARGS "rdclass, type, source, target" #define FROMSTRUCTARGS "rdclass, type, source, target"
#define FROMSTRUCTCLASS "rdclass" #define FROMSTRUCTCLASS "rdclass"
#define FROMSTRUCTTYPE "type" #define FROMSTRUCTTYPE "type"
@@ -104,14 +111,14 @@ char copyright[] =
" * purpose with or without fee is hereby granted, provided that the above\n" " * purpose with or without fee is hereby granted, provided that the above\n"
" * copyright notice and this permission notice appear in all copies.\n" " * copyright notice and this permission notice appear in all copies.\n"
" *\n" " *\n"
" * THE SOFTWARE IS PROVIDED \"AS IS\" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS\n" " * THE SOFTWARE IS PROVIDED \"AS IS\" AND INTERNET SOFTWARE CONSORTIUM\n"
" * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES\n" " * DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL\n"
" * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE\n" " * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL\n"
" * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL\n" " * INTERNET SOFTWARE CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT,\n"
" * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR\n" " * INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING\n"
" * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS\n" " * FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,\n"
" * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS\n" " * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION\n"
" * SOFTWARE.\n" " * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.\n"
" */\n" " */\n"
"\n" "\n"
"/***************\n" "/***************\n"
@@ -372,8 +379,9 @@ add(int rdclass, char *classname, int type, char *typename, char *dirname) {
else else
types = newtt; types = newtt;
/* do a class switch for this type */ /*
* Do a class switch for this type.
*/
if (rdclass == 0) if (rdclass == 0)
return; return;
@@ -585,8 +593,10 @@ main(int argc, char **argv) {
#define PRINT_COMMA(x) (x == 255 ? "" : ",") #define PRINT_COMMA(x) (x == 255 ? "" : ",")
#define METANOTQUESTION "DNS_RDATATYPEATTR_META | DNS_RDATATYPEATTR_NOTQUESTION" #define METANOTQUESTION "DNS_RDATATYPEATTR_META | " \
#define METAQUESTIONONLY "DNS_RDATATYPEATTR_META | DNS_RDATATYPEATTR_QUESTIONONLY" "DNS_RDATATYPEATTR_NOTQUESTION"
#define METAQUESTIONONLY "DNS_RDATATYPEATTR_META | " \
"DNS_RDATATYPEATTR_QUESTIONONLY"
#define RESERVED "DNS_RDATATYPEATTR_RESERVED" #define RESERVED "DNS_RDATATYPEATTR_RESERVED"
/* /*
@@ -649,14 +659,16 @@ main(int argc, char **argv) {
printf("#define RDATATYPE_COMPARE(_s, _d, _tn, _tp) \\\n"); printf("#define RDATATYPE_COMPARE(_s, _d, _tn, _tp) \\\n");
printf("\tdo { \\\n"); printf("\tdo { \\\n");
printf("\t\tif (strcasecmp(_s,(_tn)) == 0) { \\\n"); printf("\t\tif (strcasecmp(_s,(_tn)) == 0) { \\\n");
printf("\t\t\tif ((typeattr[_d].flags & DNS_RDATATYPEATTR_RESERVED) != 0) \\\n"); printf("\t\t\tif ((typeattr[_d].flags & "
"DNS_RDATATYPEATTR_RESERVED) != 0) \\\n");
printf("\t\t\t\treturn (ISC_R_NOTIMPLEMENTED); \\\n"); printf("\t\t\t\treturn (ISC_R_NOTIMPLEMENTED); \\\n");
printf("\t\t\t*(_tp) = _d; \\\n"); printf("\t\t\t*(_tp) = _d; \\\n");
printf("\t\t\treturn (ISC_R_SUCCESS); \\\n"); printf("\t\t\treturn (ISC_R_SUCCESS); \\\n");
printf("\t\t} \\\n"); printf("\t\t} \\\n");
printf("\t} while (0)\n\n"); printf("\t} while (0)\n\n");
printf("#define RDATATYPE_FROMTEXT_SW(_hash,_typename,_typep) \\\n"); printf("#define RDATATYPE_FROMTEXT_SW(_hash,_typename,_typep) "
"\\\n");
printf("\tswitch (_hash) { \\\n"); printf("\tswitch (_hash) { \\\n");
for (i = 0 ; i <= 255 ; i++) { for (i = 0 ; i <= 255 ; i++) {
ttn = &typenames[i]; ttn = &typenames[i];
@@ -679,7 +691,9 @@ main(int argc, char **argv) {
if (ttn2->sorted != 0) if (ttn2->sorted != 0)
continue; continue;
if (hash == HASH(ttn2->typename)) { if (hash == HASH(ttn2->typename)) {
printf("\t\t\tRDATATYPE_COMPARE(\"%s\", %u, _typename, _typep); \\\n", printf("\t\t\tRDATATYPE_COMPARE"
"(\"%s\", %u, "
"_typename, _typep); \\\n",
ttn2->typename, j); ttn2->typename, j);
ttn2->sorted = 1; ttn2->sorted = 1;
} }
@@ -713,7 +727,8 @@ main(int argc, char **argv) {
lasttype = 0; lasttype = 0;
for (tt = types; tt != NULL ; tt = tt->next) for (tt = types; tt != NULL ; tt = tt->next)
if (tt->type != lasttype) if (tt->type != lasttype)
fprintf(stdout, "\t dns_rdatatype_%s = %d,%s\n", fprintf(stdout,
"\t dns_rdatatype_%s = %d,%s\n",
funname(tt->typename, buf1), funname(tt->typename, buf1),
lasttype = tt->type, lasttype = tt->type,
tt->next != NULL ? " \\" : ""); tt->next != NULL ? " \\" : "");

View File

@@ -15,7 +15,7 @@
* SOFTWARE. * SOFTWARE.
*/ */
/* $Id: rdata.c,v 1.87 2000/05/09 12:07:32 tale Exp $ */ /* $Id: rdata.c,v 1.88 2000/05/09 22:22:12 tale Exp $ */
#include <config.h> #include <config.h>
@@ -812,8 +812,8 @@ dns_rdatatype_fromtext(dns_rdatatype_t *typep, isc_textregion_t *source) {
if (n == 0) if (n == 0)
return (DNS_R_UNKNOWN); return (DNS_R_UNKNOWN);
a = tolower(source->base[0]); a = tolower((unsigned char)source->base[0]);
b = tolower(source->base[n - 1]); b = tolower((unsigned char)source->base[n - 1]);
hash = ((a + n) * b) % 256; hash = ((a + n) * b) % 256;
@@ -1308,10 +1308,14 @@ compare_region(isc_region_t *r1, isc_region_t *r2) {
static int static int
hexvalue(char value) { hexvalue(char value) {
char *s; char *s;
if (!isascii(value & 0xff)) unsigned char c;
c = (unsigned char)value;
if (!isascii(c))
return (-1); return (-1);
if (isupper(value & 0xff)) if (isupper(c))
value = tolower(value); c = tolower(c);
if ((s = strchr(hexdigits, value)) == NULL) if ((s = strchr(hexdigits, value)) == NULL)
return (-1); return (-1);
return (s - hexdigits); return (s - hexdigits);
@@ -1320,7 +1324,12 @@ hexvalue(char value) {
static int static int
decvalue(char value) { decvalue(char value) {
char *s; char *s;
if (!isascii(value&0xff))
/*
* isascii() is valid for full range of int values, no need to
* mask or cast.
*/
if (!isascii(value))
return (-1); return (-1);
if ((s = strchr(decdigits, value)) == NULL) if ((s = strchr(decdigits, value)) == NULL)
return (-1); return (-1);
@@ -1328,7 +1337,8 @@ decvalue(char value) {
} }
static const char atob_digits[86] = static const char atob_digits[86] =
"!\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstu"; "!\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`" \
"abcdefghijklmnopqrstu";
/* /*
* Subroutines to convert between 8 bit binary bytes and printable ASCII. * Subroutines to convert between 8 bit binary bytes and printable ASCII.
* Computes the number of bytes, and three kinds of simple checksums. * Computes the number of bytes, and three kinds of simple checksums.

View File

@@ -19,7 +19,7 @@
/* /*
* Principal Author: Brian Wellington * Principal Author: Brian Wellington
* $Id: openssldh_link.c,v 1.12 2000/05/08 14:37:09 tale Exp $ * $Id: openssldh_link.c,v 1.13 2000/05/09 22:22:16 tale Exp $
*/ */
#if defined(OPENSSL) #if defined(OPENSSL)
@@ -687,11 +687,11 @@ BN_fromhex(BIGNUM *b, const char *str) {
char *s; char *s;
unsigned int high, low; unsigned int high, low;
s = strchr(hexdigits, tolower(str[i])); s = strchr(hexdigits, tolower((unsigned char)str[i]));
RUNTIME_CHECK(s != NULL); RUNTIME_CHECK(s != NULL);
high = s - hexdigits; high = s - hexdigits;
s = strchr(hexdigits, tolower(str[i + 1])); s = strchr(hexdigits, tolower((unsigned char)str[i + 1]));
RUNTIME_CHECK(s != NULL); RUNTIME_CHECK(s != NULL);
low = s - hexdigits; low = s - hexdigits;

View File

@@ -109,6 +109,9 @@ dns_ttl_totext(isc_uint32_t src, isc_boolean_t verbose, isc_buffer_t *target) {
/* /*
* The unit letter is the last character in the * The unit letter is the last character in the
* used region of the buffer. * used region of the buffer.
*
* toupper() does not need its argument to be masked of cast
* here because region.base is type unsigned char *.
*/ */
isc_buffer_usedregion(target, &region); isc_buffer_usedregion(target, &region);
region.base[region.length - 1] = region.base[region.length - 1] =

View File

@@ -70,7 +70,7 @@
#if defined(LIBC_SCCS) && !defined(lint) #if defined(LIBC_SCCS) && !defined(lint)
static char sccsid[] = "@(#)inet_addr.c 8.1 (Berkeley) 6/17/93"; static char sccsid[] = "@(#)inet_addr.c 8.1 (Berkeley) 6/17/93";
static char rcsid[] = "$Id: inet_aton.c,v 1.8 1999/10/29 04:25:11 marka Exp $"; static char rcsid[] = "$Id: inet_aton.c,v 1.9 2000/05/09 22:22:18 tale Exp $";
#endif /* LIBC_SCCS and not lint */ #endif /* LIBC_SCCS and not lint */
#include <config.h> #include <config.h>
@@ -88,8 +88,7 @@ static char rcsid[] = "$Id: inet_aton.c,v 1.8 1999/10/29 04:25:11 marka Exp $";
* cannot distinguish between failure and a local broadcast address. * cannot distinguish between failure and a local broadcast address.
*/ */
int int
isc_net_aton(const char *cp, struct in_addr *addr) isc_net_aton(const char *cp, struct in_addr *addr) {
{
unsigned long val; unsigned long val;
int base, n; int base, n;
char c; char c;
@@ -117,16 +116,21 @@ isc_net_aton(const char *cp, struct in_addr *addr)
} }
} }
for (;;) { for (;;) {
if (isascii(c & 0xff) && isdigit(c & 0xff)) { /*
* isascii() is valid for all integer values, and
* when it is true, c is known to be in scope
* for isdigit(). No cast necessary. Similar
* comment applies for later ctype uses.
*/
if (isascii(c) && isdigit(c)) {
if (base == 8 && (c == '8' || c == '9')) if (base == 8 && (c == '8' || c == '9'))
return (0); return (0);
val = (val * base) + (c - '0'); val = (val * base) + (c - '0');
c = *++cp; c = *++cp;
digit = 1; digit = 1;
} else if (base == 16 && isascii(c & 0xff) && } else if (base == 16 && isascii(c) && isxdigit(c)) {
isxdigit(c & 0xff)) {
val = (val << 4) | val = (val << 4) |
(c + 10 - (islower(c & 0xff) ? 'a' : 'A')); (c + 10 - (islower(c) ? 'a' : 'A'));
c = *++cp; c = *++cp;
digit = 1; digit = 1;
} else } else
@@ -149,7 +153,7 @@ isc_net_aton(const char *cp, struct in_addr *addr)
/* /*
* Check for trailing characters. * Check for trailing characters.
*/ */
if (c != '\0' && (!isascii(c & 0xff) || !isspace(c & 0xff))) if (c != '\0' && (!isascii(c) || !isspace(c)))
return (0); return (0);
/* /*
* Did we get a valid digit? * Did we get a valid digit?

View File

@@ -489,7 +489,7 @@ isc_lex_gettoken(isc_lex_t *lex, unsigned int options, isc_token_t *tokenp) {
tokenp->type = isc_tokentype_special; tokenp->type = isc_tokentype_special;
tokenp->value.as_char = c; tokenp->value.as_char = c;
done = ISC_TRUE; done = ISC_TRUE;
} else if (isdigit(c) && } else if (isdigit((unsigned char)c) &&
(options & ISC_LEXOPT_NUMBER) != 0) { (options & ISC_LEXOPT_NUMBER) != 0) {
lex->last_was_eol = ISC_FALSE; lex->last_was_eol = ISC_FALSE;
state = lexstate_number; state = lexstate_number;
@@ -508,7 +508,7 @@ isc_lex_gettoken(isc_lex_t *lex, unsigned int options, isc_token_t *tokenp) {
lex->last_was_eol = ISC_TRUE; lex->last_was_eol = ISC_TRUE;
break; break;
case lexstate_number: case lexstate_number:
if (!isdigit(c)) { if (c == EOF || !isdigit((unsigned char)c)) {
if (c == ' ' || c == '\t' || c == '\r' || if (c == ' ' || c == '\t' || c == '\r' ||
c == '\n' || c == EOF || c == '\n' || c == EOF ||
lex->specials[c]) { lex->specials[c]) {

View File

@@ -97,7 +97,9 @@ isc_print_vsnprintf(char *str, size_t size, const char *format, va_list ap) {
} }
format++; format++;
/* reset flags */ /*
* Reset flags.
*/
dot = neg = space = plus = left = zero = alt = h = l = q = 0; dot = neg = space = plus = left = zero = alt = h = l = q = 0;
width = precision = 0; width = precision = 0;
head = ""; head = "";
@@ -127,24 +129,28 @@ isc_print_vsnprintf(char *str, size_t size, const char *format, va_list ap) {
break; break;
} while (1); } while (1);
/* width */ /*
* Width.
*/
if (*format == '*') { if (*format == '*') {
width = va_arg(ap, int); width = va_arg(ap, int);
format++; format++;
} else if (isdigit(*format)) { } else if (isdigit((unsigned char)*format)) {
char *e; char *e;
width = strtoul(format, &e, 10); width = strtoul(format, &e, 10);
format = e; format = e;
} }
/* precision */ /*
* Precision.
*/
if (*format == '.') { if (*format == '.') {
format++; format++;
dot = 1; dot = 1;
if (*format == '*') { if (*format == '*') {
precision = va_arg(ap, int); precision = va_arg(ap, int);
format++; format++;
} else if (isdigit(*format)) { } else if (isdigit((unsigned char)*format)) {
char *e; char *e;
precision = strtoul(format, &e, 10); precision = strtoul(format, &e, 10);
format = e; format = e;
@@ -346,7 +352,9 @@ isc_print_vsnprintf(char *str, size_t size, const char *format, va_list ap) {
REQUIRE(cp != NULL); REQUIRE(cp != NULL);
if (precision != 0) { if (precision != 0) {
/* cp need not be NULL terminated */ /*
* cp need not be NULL terminated.
*/
char *tp; char *tp;
unsigned long n; unsigned long n;

View File

@@ -138,8 +138,7 @@ hash(const char *key, isc_boolean_t case_sensitive) {
} else { } else {
for (s = key; *s != '\0'; s++) { for (s = key; *s != '\0'; s++) {
c = *s; c = *s;
if (isascii(c) && isupper(c)) c = tolower((unsigned char)c);
c = tolower(c);
h = ( h << 4 ) + c; h = ( h << 4 ) + c;
if ((g = ( h & 0xf0000000 )) != 0) { if ((g = ( h & 0xf0000000 )) != 0) {
h = h ^ (g >> 24); h = h ^ (g >> 24);

View File

@@ -96,8 +96,7 @@ lwres_create_addr(const char *buff, lwres_addr_t *addr);
* that caused the reading to stop. * that caused the reading to stop.
*/ */
static int static int
getword(FILE *fp, char *buffer, size_t size) getword(FILE *fp, char *buffer, size_t size) {
{
int ch; int ch;
char *p = buffer; char *p = buffer;
@@ -107,7 +106,7 @@ getword(FILE *fp, char *buffer, size_t size)
*p = '\0'; *p = '\0';
ch = fgetc(fp); ch = fgetc(fp);
while (ch != '\n' && isspace(ch)) while (ch != '\n' && ch != EOF && isspace((unsigned char)ch))
ch = fgetc(fp); ch = fgetc(fp);
if (ch == EOF) if (ch == EOF)
@@ -116,10 +115,10 @@ getword(FILE *fp, char *buffer, size_t size)
do { do {
*p = '\0'; *p = '\0';
if (ch == EOF || isspace(ch)) if (ch == EOF || isspace((unsigned char)ch))
break; break;
else if ((size_t) (p - buffer) == size - 1) else if ((size_t) (p - buffer) == size - 1)
return (EOF); /* not enough space */ return (EOF); /* Not enough space. */
*p++ = (char)ch; *p++ = (char)ch;
ch = fgetc(fp); ch = fgetc(fp);
@@ -129,8 +128,7 @@ getword(FILE *fp, char *buffer, size_t size)
} }
static void static void
lwres_resetaddr(lwres_addr_t *addr) lwres_resetaddr(lwres_addr_t *addr) {
{
REQUIRE(addr != NULL); REQUIRE(addr != NULL);
memset(addr->address, 0, LWRES_ADDR_MAXLEN); memset(addr->address, 0, LWRES_ADDR_MAXLEN);
@@ -139,8 +137,7 @@ lwres_resetaddr(lwres_addr_t *addr)
} }
static char * static char *
lwres_strdup(lwres_context_t *ctx, const char *str) lwres_strdup(lwres_context_t *ctx, const char *str) {
{
char *p; char *p;
REQUIRE(str != NULL); REQUIRE(str != NULL);
@@ -154,8 +151,7 @@ lwres_strdup(lwres_context_t *ctx, const char *str)
} }
void void
lwres_conf_init(lwres_context_t *ctx) lwres_conf_init(lwres_context_t *ctx) {
{
int i; int i;
lwres_conf_t *confdata; lwres_conf_t *confdata;
@@ -183,8 +179,7 @@ lwres_conf_init(lwres_context_t *ctx)
} }
void void
lwres_conf_clear(lwres_context_t *ctx) lwres_conf_clear(lwres_context_t *ctx) {
{
int i; int i;
lwres_conf_t *confdata; lwres_conf_t *confdata;
@@ -223,8 +218,7 @@ lwres_conf_clear(lwres_context_t *ctx)
} }
static lwres_result_t static lwres_result_t
lwres_conf_parsenameserver(lwres_context_t *ctx, FILE *fp) lwres_conf_parsenameserver(lwres_context_t *ctx, FILE *fp) {
{
char word[LWRES_CONFMAXLINELEN]; char word[LWRES_CONFMAXLINELEN];
int res; int res;
lwres_conf_t *confdata; lwres_conf_t *confdata;
@@ -236,9 +230,9 @@ lwres_conf_parsenameserver(lwres_context_t *ctx, FILE *fp)
res = getword(fp, word, sizeof(word)); res = getword(fp, word, sizeof(word));
if (strlen(word) == 0) if (strlen(word) == 0)
return (LWRES_R_FAILURE); /* nothing on line */ return (LWRES_R_FAILURE); /* Nothing on line. */
else if (res != EOF && res != '\n') else if (res != EOF && res != '\n')
return (LWRES_R_FAILURE); /* extra junk on line */ return (LWRES_R_FAILURE); /* Extra junk on line. */
res = lwres_create_addr(word, res = lwres_create_addr(word,
&confdata->nameservers[confdata->nsnext++]); &confdata->nameservers[confdata->nsnext++]);
@@ -249,8 +243,7 @@ lwres_conf_parsenameserver(lwres_context_t *ctx, FILE *fp)
} }
static lwres_result_t static lwres_result_t
lwres_conf_parsedomain(lwres_context_t *ctx, FILE *fp) lwres_conf_parsedomain(lwres_context_t *ctx, FILE *fp) {
{
char word[LWRES_CONFMAXLINELEN]; char word[LWRES_CONFMAXLINELEN];
int res, i; int res, i;
lwres_conf_t *confdata; lwres_conf_t *confdata;
@@ -259,15 +252,17 @@ lwres_conf_parsedomain(lwres_context_t *ctx, FILE *fp)
res = getword(fp, word, sizeof(word)); res = getword(fp, word, sizeof(word));
if (strlen(word) == 0) if (strlen(word) == 0)
return (LWRES_R_FAILURE); /* nothing else on line */ return (LWRES_R_FAILURE); /* Nothing else on line. */
else if (res != EOF && res != '\n') else if (res != EOF && res != '\n')
return (LWRES_R_FAILURE); /* extra junk on line */ return (LWRES_R_FAILURE); /* Extra junk on line. */
if (confdata->domainname != NULL) if (confdata->domainname != NULL)
CTXFREE(confdata->domainname, CTXFREE(confdata->domainname,
strlen(confdata->domainname) + 1); /* */ strlen(confdata->domainname) + 1); /* */
/* search and domain are mutually exclusive */ /*
* Search and domain are mutually exclusive.
*/
for (i = 0 ; i < LWRES_CONFMAXSEARCH ; i++) { for (i = 0 ; i < LWRES_CONFMAXSEARCH ; i++) {
if (confdata->search[i] != NULL) { if (confdata->search[i] != NULL) {
CTXFREE(confdata->search[i], CTXFREE(confdata->search[i],
@@ -286,8 +281,7 @@ lwres_conf_parsedomain(lwres_context_t *ctx, FILE *fp)
} }
static lwres_result_t static lwres_result_t
lwres_conf_parsesearch(lwres_context_t *ctx, FILE *fp) lwres_conf_parsesearch(lwres_context_t *ctx, FILE *fp) {
{
int idx, delim; int idx, delim;
char word[LWRES_CONFMAXLINELEN]; char word[LWRES_CONFMAXLINELEN];
lwres_conf_t *confdata; lwres_conf_t *confdata;
@@ -295,13 +289,17 @@ lwres_conf_parsesearch(lwres_context_t *ctx, FILE *fp)
confdata = &ctx->confdata; confdata = &ctx->confdata;
if (confdata->domainname != NULL) { if (confdata->domainname != NULL) {
/* search and domain are mutually exclusive */ /*
* Search and domain are mutually exclusive.
*/
CTXFREE(confdata->domainname, CTXFREE(confdata->domainname,
strlen(confdata->domainname) + 1); strlen(confdata->domainname) + 1);
confdata->domainname = NULL; confdata->domainname = NULL;
} }
/* remove any previous search definitions. */ /*
* Remove any previous search definitions.
*/
for (idx = 0 ; idx < LWRES_CONFMAXSEARCH ; idx++) { for (idx = 0 ; idx < LWRES_CONFMAXSEARCH ; idx++) {
if (confdata->search[idx] != NULL) { if (confdata->search[idx] != NULL) {
CTXFREE(confdata->search[idx], CTXFREE(confdata->search[idx],
@@ -313,12 +311,12 @@ lwres_conf_parsesearch(lwres_context_t *ctx, FILE *fp)
delim = getword(fp, word, sizeof(word)); delim = getword(fp, word, sizeof(word));
if (strlen(word) == 0) if (strlen(word) == 0)
return (LWRES_R_FAILURE); /* nothing else on line */ return (LWRES_R_FAILURE); /* Nothing else on line. */
idx = 0; idx = 0;
while (strlen(word) > 0) { while (strlen(word) > 0) {
if (confdata->searchnxt == LWRES_CONFMAXSEARCH) if (confdata->searchnxt == LWRES_CONFMAXSEARCH)
return (LWRES_R_FAILURE); /* too many domains */ return (LWRES_R_FAILURE); /* Too many domains. */
confdata->search[idx] = lwres_strdup(ctx, word); confdata->search[idx] = lwres_strdup(ctx, word);
if (confdata->search[idx] == NULL) if (confdata->search[idx] == NULL)
@@ -336,8 +334,7 @@ lwres_conf_parsesearch(lwres_context_t *ctx, FILE *fp)
} }
static lwres_result_t static lwres_result_t
lwres_create_addr(const char *buffer, lwres_addr_t *addr) lwres_create_addr(const char *buffer, lwres_addr_t *addr) {
{
unsigned char addrbuff[NS_IN6ADDRSZ]; unsigned char addrbuff[NS_IN6ADDRSZ];
unsigned int len; unsigned int len;
@@ -352,7 +349,7 @@ lwres_create_addr(const char *buffer, lwres_addr_t *addr)
len = 16; len = 16;
#endif #endif
} else { } else {
return (LWRES_R_FAILURE); /* unrecongnised format */ return (LWRES_R_FAILURE); /* Unrecongnised format. */
} }
memcpy((void *)addr->address, addrbuff, len); memcpy((void *)addr->address, addrbuff, len);
@@ -361,8 +358,7 @@ lwres_create_addr(const char *buffer, lwres_addr_t *addr)
} }
static lwres_result_t static lwres_result_t
lwres_conf_parsesortlist(lwres_context_t *ctx, FILE *fp) lwres_conf_parsesortlist(lwres_context_t *ctx, FILE *fp) {
{
int delim, res, idx; int delim, res, idx;
char word[LWRES_CONFMAXLINELEN]; char word[LWRES_CONFMAXLINELEN];
char *p; char *p;
@@ -372,11 +368,11 @@ lwres_conf_parsesortlist(lwres_context_t *ctx, FILE *fp)
delim = getword(fp, word, sizeof(word)); delim = getword(fp, word, sizeof(word));
if (strlen(word) == 0) if (strlen(word) == 0)
return (LWRES_R_FAILURE); /* empty line after keyword */ return (LWRES_R_FAILURE); /* Empty line after keyword. */
while (strlen(word) > 0) { while (strlen(word) > 0) {
if (confdata->sortlistnxt == LWRES_CONFMAXSORTLIST) if (confdata->sortlistnxt == LWRES_CONFMAXSORTLIST)
return (LWRES_R_FAILURE); /* too many values. */ return (LWRES_R_FAILURE); /* Too many values. */
p = strchr(word, '/'); p = strchr(word, '/');
if (p != NULL) if (p != NULL)
@@ -393,7 +389,9 @@ lwres_conf_parsesortlist(lwres_context_t *ctx, FILE *fp)
if (res != LWRES_R_SUCCESS) if (res != LWRES_R_SUCCESS)
return (res); return (res);
} else { } else {
/* Make up a mask. */ /*
* Make up a mask.
*/
confdata->sortlist[idx].mask = confdata->sortlist[idx].mask =
confdata->sortlist[idx].addr; confdata->sortlist[idx].addr;
@@ -426,7 +424,7 @@ lwres_conf_parseoption(lwres_context_t *ctx, FILE *fp)
delim = getword(fp, word, sizeof(word)); delim = getword(fp, word, sizeof(word));
if (strlen(word) == 0) if (strlen(word) == 0)
return (LWRES_R_FAILURE); /* empty line after keyword */ return (LWRES_R_FAILURE); /* Empty line after keyword. */
while (strlen(word) > 0) { while (strlen(word) > 0) {
if (strcmp("debug", word) == 0) { if (strcmp("debug", word) == 0) {
@@ -435,7 +433,7 @@ lwres_conf_parseoption(lwres_context_t *ctx, FILE *fp)
confdata->no_tld_query = 1; confdata->no_tld_query = 1;
} else if (strncmp("ndots:", word, 6) == 0) { } else if (strncmp("ndots:", word, 6) == 0) {
ndots = strtol(word + 6, &p, 10); ndots = strtol(word + 6, &p, 10);
if (*p != '\0') /* bad string */ if (*p != '\0') /* Bad string. */
return (LWRES_R_FAILURE); return (LWRES_R_FAILURE);
confdata->ndots = ndots; confdata->ndots = ndots;
} }
@@ -450,8 +448,7 @@ lwres_conf_parseoption(lwres_context_t *ctx, FILE *fp)
} }
lwres_result_t lwres_result_t
lwres_conf_parse(lwres_context_t *ctx, const char *filename) lwres_conf_parse(lwres_context_t *ctx, const char *filename) {
{
FILE *fp = NULL; FILE *fp = NULL;
char word[256]; char word[256];
int delim; int delim;
@@ -495,8 +492,7 @@ lwres_conf_parse(lwres_context_t *ctx, const char *filename)
} }
lwres_result_t lwres_result_t
lwres_conf_print(lwres_context_t *ctx, FILE *fp) lwres_conf_print(lwres_context_t *ctx, FILE *fp) {
{
int i; int i;
char tmp[sizeof "ffff:ffff:ffff:ffff:ffff:ffff:255.255.255.255"]; char tmp[sizeof "ffff:ffff:ffff:ffff:ffff:ffff:255.255.255.255"];
const char *p; const char *p;
@@ -568,8 +564,7 @@ lwres_conf_print(lwres_context_t *ctx, FILE *fp)
} }
lwres_conf_t * lwres_conf_t *
lwres_conf_get(lwres_context_t *ctx) lwres_conf_get(lwres_context_t *ctx) {
{
REQUIRE(ctx != NULL); REQUIRE(ctx != NULL);
return (&ctx->confdata); return (&ctx->confdata);

View File

@@ -70,7 +70,7 @@
#if defined(LIBC_SCCS) && !defined(lint) #if defined(LIBC_SCCS) && !defined(lint)
static char sccsid[] = "@(#)inet_addr.c 8.1 (Berkeley) 6/17/93"; static char sccsid[] = "@(#)inet_addr.c 8.1 (Berkeley) 6/17/93";
static char rcsid[] = "$Id: lwinetaton.c,v 1.2 2000/02/04 06:50:06 halley Exp $"; static char rcsid[] = "$Id: lwinetaton.c,v 1.3 2000/05/09 22:22:24 tale Exp $";
#endif /* LIBC_SCCS and not lint */ #endif /* LIBC_SCCS and not lint */
#include <config.h> #include <config.h>
@@ -90,8 +90,7 @@ static char rcsid[] = "$Id: lwinetaton.c,v 1.2 2000/02/04 06:50:06 halley Exp $"
* cannot distinguish between failure and a local broadcast address. * cannot distinguish between failure and a local broadcast address.
*/ */
int int
lwres_net_aton(const char *cp, struct in_addr *addr) lwres_net_aton(const char *cp, struct in_addr *addr) {
{
unsigned long val; unsigned long val;
int base, n; int base, n;
char c; char c;
@@ -119,16 +118,21 @@ lwres_net_aton(const char *cp, struct in_addr *addr)
} }
} }
for (;;) { for (;;) {
if (isascii(c & 0xff) && isdigit(c & 0xff)) { /*
* isascii() is valid for all integer values, and
* when it is true, c is known to be in scope
* for isdigit(). No cast necessary. Similar
* comment applies for later ctype uses.
*/
if (isascii(c) && isdigit(c)) {
if (base == 8 && (c == '8' || c == '9')) if (base == 8 && (c == '8' || c == '9'))
return (0); return (0);
val = (val * base) + (c - '0'); val = (val * base) + (c - '0');
c = *++cp; c = *++cp;
digit = 1; digit = 1;
} else if (base == 16 && isascii(c & 0xff) && } else if (base == 16 && isascii(c) && isxdigit(c)) {
isxdigit(c & 0xff)) {
val = (val << 4) | val = (val << 4) |
(c + 10 - (islower(c & 0xff) ? 'a' : 'A')); (c + 10 - (islower(c) ? 'a' : 'A'));
c = *++cp; c = *++cp;
digit = 1; digit = 1;
} else } else
@@ -151,7 +155,7 @@ lwres_net_aton(const char *cp, struct in_addr *addr)
/* /*
* Check for trailing characters. * Check for trailing characters.
*/ */
if (c != '\0' && (!isascii(c & 0xff) || !isspace(c & 0xff))) if (c != '\0' && (!isascii(c) || !isspace(c)))
return (0); return (0);
/* /*
* Did we get a valid digit? * Did we get a valid digit?

View File

@@ -725,7 +725,7 @@ t_eval(char *filename, int (*func)(char **), int nargs) {
/* /*
* Skip comment lines. * Skip comment lines.
*/ */
if ((isspace((int)*p)) || (*p == '#')) if ((isspace((unsigned char)*p)) || (*p == '#'))
continue; continue;
cnt = t_bustline(p, tokens); cnt = t_bustline(p, tokens);