2
0
mirror of https://gitlab.isc.org/isc-projects/bind9 synced 2025-08-31 14:35:26 +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

@@ -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) {
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;
}
}