diff --git a/CHANGES b/CHANGES index 59aa8c45da..8c293f19eb 100644 --- a/CHANGES +++ b/CHANGES @@ -1,3 +1,5 @@ +1485. [bug] gen failed to handle high type values. [RT #6225] + 1484. [bug] The number of records reported after a AXFR was wrong. [RT #6229] diff --git a/lib/dns/gen.c b/lib/dns/gen.c index dae8b15b0e..93a7c19dbc 100644 --- a/lib/dns/gen.c +++ b/lib/dns/gen.c @@ -15,7 +15,7 @@ * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -/* $Id: gen.c,v 1.68 2002/03/20 17:12:28 marka Exp $ */ +/* $Id: gen.c,v 1.69 2003/07/17 08:05:15 marka Exp $ */ #include @@ -110,6 +110,8 @@ const char copyright[] = " ***************/\n" "\n"; +#define TYPENAMES 256 + struct cc { struct cc *next; int rdclass; @@ -130,7 +132,10 @@ struct ttnam { char macroname[11]; char attr[256]; unsigned int sorted; -} typenames[256]; + int type; +} typenames[TYPENAMES]; + +int maxtype = -1; char * upper(char *); @@ -274,25 +279,48 @@ dodecl(char *type, char *function, char *args) { funname(tt->typename, buf1), args); } +static struct ttnam * +find_typename(int type) { + int i; + + for (i = 0; i < TYPENAMES; i++) { + if (typenames[i].typename[0] != 0 && + typenames[i].type == type) + return (&typenames[i]); + } + return (NULL); +} + void insert_into_typenames(int type, const char *typename, const char *attr) { - struct ttnam *ttn; - int c; + struct ttnam *ttn = NULL; + int c, i; char tmp[256]; - ttn = &typenames[type]; - if (ttn->typename[0] == 0) { - if (strlen(typename) > sizeof(ttn->typename) - 1) { - fprintf(stderr, "Error: type name %s is too long\n", - typename); + for (i = 0; i < TYPENAMES; i++) { + if (typenames[i].typename[0] != 0 && + typenames[i].type == type && + strcmp(typename, typenames[i].typename) != 0) { + fprintf(stderr, + "Error: type %d has two names: %s, %s\n", + type, typenames[i].typename, typename); exit(1); } - strcpy(ttn->typename, typename); - } else if (strcmp(typename, ttn->typename) != 0) { - fprintf(stderr, "Error: type %d has two names: %s, %s\n", - type, ttn->typename, typename); + if (typenames[i].typename[0] == 0 && ttn == NULL) + ttn = &typenames[i]; + } + if (ttn == NULL) { + fprintf(stderr, "Error: typenames array too small\n"); exit(1); } + + if (strlen(typename) > sizeof(ttn->typename) - 1) { + fprintf(stderr, "Error: type name %s is too long\n", + typename); + exit(1); + } + strcpy(ttn->typename, typename); + ttn->type = type; strcpy(ttn->macroname, ttn->typename); c = strlen(ttn->macroname); @@ -320,6 +348,8 @@ insert_into_typenames(int type, const char *typename, const char *attr) { } strcpy(ttn->attr, attr); ttn->sorted = 0; + if (maxtype < type) + maxtype = type; } void @@ -469,7 +499,7 @@ main(int argc, char **argv) { char *file = NULL; isc_dir_t dir; - for (i = 0; i <= 255; i++) + for (i = 0; i < TYPENAMES; i++) memset(&typenames[i], 0, sizeof(typenames[i])); strcpy(srcdir, ""); @@ -596,7 +626,7 @@ main(int argc, char **argv) { * attributes. */ -#define PRINT_COMMA(x) (x == 255 ? "" : ",") +#define PRINT_COMMA(x) (x == maxtype ? "" : ",") #define METANOTQUESTION "DNS_RDATATYPEATTR_META | " \ "DNS_RDATATYPEATTR_NOTQUESTION" @@ -626,9 +656,9 @@ main(int argc, char **argv) { fprintf(stdout, "\tunsigned int flags;\n"); fprintf(stdout, "} typeattr_t;\n"); fprintf(stdout, "static typeattr_t typeattr[] = {\n"); - for (i = 0; i <= 255; i++) { - ttn = &typenames[i]; - if (ttn->typename[0] == 0) { + for (i = 0; i <= maxtype; i++) { + ttn = find_typename(i); + if (ttn == NULL) { const char *attrs; if (i >= 128 && i < 255) attrs = "DNS_RDATATYPEATTR_UNKNOWN | " @@ -636,7 +666,7 @@ main(int argc, char **argv) { else attrs = "DNS_RDATATYPEATTR_UNKNOWN"; fprintf(stdout, "\t{ \"TYPE%d\", %s}%s\n", - i, attrs, PRINT_COMMA(i)); + i, attrs, PRINT_COMMA(i)); } else { fprintf(stdout, "\t{ \"%s\", %s }%s\n", upper(ttn->typename), @@ -646,16 +676,6 @@ main(int argc, char **argv) { } fprintf(stdout, "};\n"); - /* - * Run through the list of types and pre-mark the unused - * ones as "sorted" so we simply ignore them below. - */ - for (i = 0; i <= 255; i++) { - ttn = &typenames[i]; - if (ttn->typename[0] == 0) - ttn->sorted = 1; - } - /* * Spit out a quick and dirty hash function. Here, * we walk through the list of type names, and calculate @@ -682,8 +702,10 @@ main(int argc, char **argv) { fprintf(stdout, "#define RDATATYPE_FROMTEXT_SW(_hash," "_typename,_length,_typep) \\\n"); fprintf(stdout, "\tswitch (_hash) { \\\n"); - for (i = 0; i <= 255; i++) { - ttn = &typenames[i]; + for (i = 0; i <= maxtype; i++) { + ttn = find_typename(i); + if (ttn == NULL) + continue; /* * Skip entries we already processed. @@ -698,15 +720,15 @@ main(int argc, char **argv) { * Find all other entries that happen to match * this hash. */ - for (j = 0; j <= 255; j++) { - ttn2 = &typenames[j]; - if (ttn2->sorted != 0) + for (j = 0; j <= maxtype; j++) { + ttn2 = find_typename(j); + if (ttn2 == NULL) continue; if (hash == HASH(ttn2->typename)) { fprintf(stdout, "\t\t\tRDATATYPE_COMPARE" "(\"%s\", %u, " "_typename, _length, _typep); \\\n", - ttn2->typename, j); + ttn2->typename, ttn2->type); ttn2->sorted = 1; } } diff --git a/lib/dns/rdata.c b/lib/dns/rdata.c index 9ad903a670..fb4c3ebc59 100644 --- a/lib/dns/rdata.c +++ b/lib/dns/rdata.c @@ -15,7 +15,7 @@ * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -/* $Id: rdata.c,v 1.175 2003/06/24 05:10:32 marka Exp $ */ +/* $Id: rdata.c,v 1.176 2003/07/17 08:05:15 marka Exp $ */ #include #include @@ -765,7 +765,7 @@ rdata_totext(dns_rdata_t *rdata, dns_rdata_textctx_t *tctx, { isc_result_t result = ISC_R_NOTIMPLEMENTED; isc_boolean_t use_default = ISC_FALSE; - char buf[sizeof("65536")]; + char buf[sizeof("65535")]; isc_region_t sr; REQUIRE(rdata != NULL); @@ -958,10 +958,9 @@ dns_rdata_digest(dns_rdata_t *rdata, dns_digestfunc_t digest, void *arg) { unsigned int dns_rdatatype_attributes(dns_rdatatype_t type) { - if (type > 255) - return (DNS_RDATATYPEATTR_UNKNOWN); - - return (typeattr[type].flags); + if (type < (sizeof(typeattr)/sizeof(typeattr[0]))) + return (typeattr[type].flags); + return (DNS_RDATATYPEATTR_UNKNOWN); } #define NUMBERSIZE sizeof("037777777777") /* 2^32-1 octal + NUL */ @@ -1107,7 +1106,7 @@ dns_rdataclass_fromtext(dns_rdataclass_t *classp, isc_textregion_t *source) { isc_result_t dns_rdataclass_totext(dns_rdataclass_t rdclass, isc_buffer_t *target) { - char buf[sizeof("CLASS65536")]; + char buf[sizeof("CLASS65535")]; switch (rdclass) { case dns_rdataclass_any: @@ -1195,14 +1194,12 @@ dns_rdatatype_fromtext(dns_rdatatype_t *typep, isc_textregion_t *source) { isc_result_t dns_rdatatype_totext(dns_rdatatype_t type, isc_buffer_t *target) { - char buf[sizeof("TYPE65536")]; + char buf[sizeof("TYPE65535")]; - if (type > 255) { - snprintf(buf, sizeof buf, "TYPE%u", type); - return (str_totext(buf, target)); - } - - return (str_totext(typeattr[type].name, target)); + if (type < (sizeof(typeattr)/sizeof(typeattr[0]))) + return (str_totext(typeattr[type].name, target)); + snprintf(buf, sizeof buf, "TYPE%u", type); + return (str_totext(buf, target)); } void