2
0
mirror of https://gitlab.isc.org/isc-projects/bind9 synced 2025-09-01 23:25:38 +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.
[RT #6229]

View File

@@ -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 <config.h>
@@ -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) {
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);
}
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);
} else if (strcmp(typename, ttn->typename) != 0) {
fprintf(stderr, "Error: type %d has two names: %s, %s\n",
type, ttn->typename, typename);
exit(1);
}
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 | "
@@ -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;
}
}

View File

@@ -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 <config.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_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);
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,16 +1194,14 @@ 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) {
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));
}
return (str_totext(typeattr[type].name, target));
}
void
dns_rdatatype_format(dns_rdatatype_t rdtype,
char *array, unsigned int size)