2
0
mirror of https://gitlab.isc.org/isc-projects/bind9 synced 2025-09-01 15:05:23 +00:00

1485. [bug] gen failed to handle high type values. [RT #6225]

This commit is contained in:
Mark Andrews
2003-07-17 08:05:15 +00:00
parent e0557d5e68
commit 471e0563c7
3 changed files with 70 additions and 49 deletions

View File

@@ -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. 1484. [bug] The number of records reported after a AXFR was wrong.
[RT #6229] [RT #6229]

View File

@@ -15,7 +15,7 @@
* WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. * 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 <config.h> #include <config.h>
@@ -110,6 +110,8 @@ const char copyright[] =
" ***************/\n" " ***************/\n"
"\n"; "\n";
#define TYPENAMES 256
struct cc { struct cc {
struct cc *next; struct cc *next;
int rdclass; int rdclass;
@@ -130,7 +132,10 @@ struct ttnam {
char macroname[11]; char macroname[11];
char attr[256]; char attr[256];
unsigned int sorted; unsigned int sorted;
} typenames[256]; int type;
} typenames[TYPENAMES];
int maxtype = -1;
char * char *
upper(char *); upper(char *);
@@ -274,25 +279,48 @@ dodecl(char *type, char *function, char *args) {
funname(tt->typename, buf1), 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 void
insert_into_typenames(int type, const char *typename, const char *attr) { insert_into_typenames(int type, const char *typename, const char *attr) {
struct ttnam *ttn; struct ttnam *ttn = NULL;
int c; int c, i;
char tmp[256]; char tmp[256];
ttn = &typenames[type]; for (i = 0; i < TYPENAMES; i++) {
if (ttn->typename[0] == 0) { if (typenames[i].typename[0] != 0 &&
if (strlen(typename) > sizeof(ttn->typename) - 1) { typenames[i].type == type &&
fprintf(stderr, "Error: type name %s is too long\n", strcmp(typename, typenames[i].typename) != 0) {
typename); fprintf(stderr,
"Error: type %d has two names: %s, %s\n",
type, typenames[i].typename, typename);
exit(1); exit(1);
} }
strcpy(ttn->typename, typename); if (typenames[i].typename[0] == 0 && ttn == NULL)
} else if (strcmp(typename, ttn->typename) != 0) { ttn = &typenames[i];
fprintf(stderr, "Error: type %d has two names: %s, %s\n", }
type, ttn->typename, typename); if (ttn == NULL) {
fprintf(stderr, "Error: typenames array too small\n");
exit(1); 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); strcpy(ttn->macroname, ttn->typename);
c = strlen(ttn->macroname); c = strlen(ttn->macroname);
@@ -320,6 +348,8 @@ insert_into_typenames(int type, const char *typename, const char *attr) {
} }
strcpy(ttn->attr, attr); strcpy(ttn->attr, attr);
ttn->sorted = 0; ttn->sorted = 0;
if (maxtype < type)
maxtype = type;
} }
void void
@@ -469,7 +499,7 @@ main(int argc, char **argv) {
char *file = NULL; char *file = NULL;
isc_dir_t dir; isc_dir_t dir;
for (i = 0; i <= 255; i++) for (i = 0; i < TYPENAMES; i++)
memset(&typenames[i], 0, sizeof(typenames[i])); memset(&typenames[i], 0, sizeof(typenames[i]));
strcpy(srcdir, ""); strcpy(srcdir, "");
@@ -596,7 +626,7 @@ main(int argc, char **argv) {
* attributes. * attributes.
*/ */
#define PRINT_COMMA(x) (x == 255 ? "" : ",") #define PRINT_COMMA(x) (x == maxtype ? "" : ",")
#define METANOTQUESTION "DNS_RDATATYPEATTR_META | " \ #define METANOTQUESTION "DNS_RDATATYPEATTR_META | " \
"DNS_RDATATYPEATTR_NOTQUESTION" "DNS_RDATATYPEATTR_NOTQUESTION"
@@ -626,9 +656,9 @@ main(int argc, char **argv) {
fprintf(stdout, "\tunsigned int flags;\n"); fprintf(stdout, "\tunsigned int flags;\n");
fprintf(stdout, "} typeattr_t;\n"); fprintf(stdout, "} typeattr_t;\n");
fprintf(stdout, "static typeattr_t typeattr[] = {\n"); fprintf(stdout, "static typeattr_t typeattr[] = {\n");
for (i = 0; i <= 255; i++) { for (i = 0; i <= maxtype; i++) {
ttn = &typenames[i]; ttn = find_typename(i);
if (ttn->typename[0] == 0) { if (ttn == NULL) {
const char *attrs; const char *attrs;
if (i >= 128 && i < 255) if (i >= 128 && i < 255)
attrs = "DNS_RDATATYPEATTR_UNKNOWN | " attrs = "DNS_RDATATYPEATTR_UNKNOWN | "
@@ -636,7 +666,7 @@ main(int argc, char **argv) {
else else
attrs = "DNS_RDATATYPEATTR_UNKNOWN"; attrs = "DNS_RDATATYPEATTR_UNKNOWN";
fprintf(stdout, "\t{ \"TYPE%d\", %s}%s\n", fprintf(stdout, "\t{ \"TYPE%d\", %s}%s\n",
i, attrs, PRINT_COMMA(i)); i, attrs, PRINT_COMMA(i));
} else { } else {
fprintf(stdout, "\t{ \"%s\", %s }%s\n", fprintf(stdout, "\t{ \"%s\", %s }%s\n",
upper(ttn->typename), upper(ttn->typename),
@@ -646,16 +676,6 @@ main(int argc, char **argv) {
} }
fprintf(stdout, "};\n"); 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, * Spit out a quick and dirty hash function. Here,
* we walk through the list of type names, and calculate * 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," fprintf(stdout, "#define RDATATYPE_FROMTEXT_SW(_hash,"
"_typename,_length,_typep) \\\n"); "_typename,_length,_typep) \\\n");
fprintf(stdout, "\tswitch (_hash) { \\\n"); fprintf(stdout, "\tswitch (_hash) { \\\n");
for (i = 0; i <= 255; i++) { for (i = 0; i <= maxtype; i++) {
ttn = &typenames[i]; ttn = find_typename(i);
if (ttn == NULL)
continue;
/* /*
* Skip entries we already processed. * Skip entries we already processed.
@@ -698,15 +720,15 @@ main(int argc, char **argv) {
* Find all other entries that happen to match * Find all other entries that happen to match
* this hash. * this hash.
*/ */
for (j = 0; j <= 255; j++) { for (j = 0; j <= maxtype; j++) {
ttn2 = &typenames[j]; ttn2 = find_typename(j);
if (ttn2->sorted != 0) if (ttn2 == NULL)
continue; continue;
if (hash == HASH(ttn2->typename)) { if (hash == HASH(ttn2->typename)) {
fprintf(stdout, "\t\t\tRDATATYPE_COMPARE" fprintf(stdout, "\t\t\tRDATATYPE_COMPARE"
"(\"%s\", %u, " "(\"%s\", %u, "
"_typename, _length, _typep); \\\n", "_typename, _length, _typep); \\\n",
ttn2->typename, j); ttn2->typename, ttn2->type);
ttn2->sorted = 1; ttn2->sorted = 1;
} }
} }

View File

@@ -15,7 +15,7 @@
* WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. * 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 <config.h> #include <config.h>
#include <ctype.h> #include <ctype.h>
@@ -765,7 +765,7 @@ rdata_totext(dns_rdata_t *rdata, dns_rdata_textctx_t *tctx,
{ {
isc_result_t result = ISC_R_NOTIMPLEMENTED; isc_result_t result = ISC_R_NOTIMPLEMENTED;
isc_boolean_t use_default = ISC_FALSE; isc_boolean_t use_default = ISC_FALSE;
char buf[sizeof("65536")]; char buf[sizeof("65535")];
isc_region_t sr; isc_region_t sr;
REQUIRE(rdata != NULL); REQUIRE(rdata != NULL);
@@ -958,10 +958,9 @@ dns_rdata_digest(dns_rdata_t *rdata, dns_digestfunc_t digest, void *arg) {
unsigned int unsigned int
dns_rdatatype_attributes(dns_rdatatype_t type) dns_rdatatype_attributes(dns_rdatatype_t type)
{ {
if (type > 255) if (type < (sizeof(typeattr)/sizeof(typeattr[0])))
return (DNS_RDATATYPEATTR_UNKNOWN); return (typeattr[type].flags);
return (DNS_RDATATYPEATTR_UNKNOWN);
return (typeattr[type].flags);
} }
#define NUMBERSIZE sizeof("037777777777") /* 2^32-1 octal + NUL */ #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 isc_result_t
dns_rdataclass_totext(dns_rdataclass_t rdclass, isc_buffer_t *target) { dns_rdataclass_totext(dns_rdataclass_t rdclass, isc_buffer_t *target) {
char buf[sizeof("CLASS65536")]; char buf[sizeof("CLASS65535")];
switch (rdclass) { switch (rdclass) {
case dns_rdataclass_any: case dns_rdataclass_any:
@@ -1195,14 +1194,12 @@ dns_rdatatype_fromtext(dns_rdatatype_t *typep, isc_textregion_t *source) {
isc_result_t isc_result_t
dns_rdatatype_totext(dns_rdatatype_t type, isc_buffer_t *target) { dns_rdatatype_totext(dns_rdatatype_t type, isc_buffer_t *target) {
char buf[sizeof("TYPE65536")]; char buf[sizeof("TYPE65535")];
if (type > 255) { if (type < (sizeof(typeattr)/sizeof(typeattr[0])))
snprintf(buf, sizeof buf, "TYPE%u", type); return (str_totext(typeattr[type].name, target));
return (str_totext(buf, target)); snprintf(buf, sizeof buf, "TYPE%u", type);
} return (str_totext(buf, target));
return (str_totext(typeattr[type].name, target));
} }
void void