2
0
mirror of https://gitlab.isc.org/isc-projects/bind9 synced 2025-09-03 08:05:21 +00:00

Merge branch '1542-silent-failure-of-build-when-creating-a-new-rr-type-if-code-is-out-of-range' into 'main'

Resolve "Silent failure of build when creating a new RR Type if CODE is out of range"

Closes #1542

See merge request isc-projects/bind9!2895
This commit is contained in:
Mark Andrews
2021-10-25 21:52:34 +00:00
2 changed files with 38 additions and 16 deletions

View File

@@ -98,6 +98,12 @@ Initial rdata hierarchy:
any_255/ any_255/
tsig_250.h tsig_250.h
#### CLASSNUMBER and TYPENUMBER
Class and type numbers must be unsigned integers. Permissable alphabet: 0 to 9,
if no match than the file is silently ignored. The number can be at most 65535,
any number higher is a build error.
#### CLASSNAME and TYPENAME #### CLASSNAME and TYPENAME
Class and type names must be from the following alphabet and less that 11 Class and type names must be from the following alphabet and less that 11

View File

@@ -127,7 +127,7 @@ static const char copyright[] = "/*\n"
#define TYPENAMES 256 #define TYPENAMES 256
#define TYPECLASSLEN 20 /* DNS mnemonic size. Must be less than 100. */ #define TYPECLASSLEN 20 /* DNS mnemonic size. Must be less than 100. */
#define TYPECLASSBUF (TYPECLASSLEN + 1) #define TYPECLASSBUF (TYPECLASSLEN + 1)
#define TYPECLASSFMT "%" STR(TYPECLASSLEN) "[-0-9a-z]_%d" #define TYPECLASSFMT "%" STR(TYPECLASSLEN) "[-0-9a-z]_%u"
#define ATTRIBUTESIZE 256 #define ATTRIBUTESIZE 256
static struct cc { static struct cc {
@@ -163,9 +163,9 @@ static void
doswitch(const char *, const char *, const char *, const char *, const char *, doswitch(const char *, const char *, const char *, const char *, const char *,
const char *); const char *);
static void static void
add(int, const char *, int, const char *, const char *); add(unsigned int, const char *, int, const char *, const char *);
static void static void
sd(int, const char *, const char *, char); sd(unsigned int, const char *, const char *, char);
static void static void
insert_into_typenames(int, const char *, const char *); insert_into_typenames(int, const char *, const char *);
@@ -370,7 +370,7 @@ insert_into_typenames(int type, const char *typebuf, const char *attr) {
} }
static void static void
add(int rdclass, const char *classbuf, int type, const char *typebuf, add(unsigned int rdclass, const char *classbuf, int type, const char *typebuf,
const char *dirbuf) { const char *dirbuf) {
struct tt *newtt = (struct tt *)malloc(sizeof(*newtt)); struct tt *newtt = (struct tt *)malloc(sizeof(*newtt));
struct tt *tt, *oldtt; struct tt *tt, *oldtt;
@@ -468,10 +468,12 @@ add(int rdclass, const char *classbuf, int type, const char *typebuf,
} }
static void static void
sd(int rdclass, const char *classbuf, const char *dirbuf, char filetype) { sd(unsigned int rdclass, const char *classbuf, const char *dirbuf,
char buf[TYPECLASSLEN + sizeof("_65535.h")]; char filetype) {
char buf[TYPECLASSLEN + sizeof("_4294967295.h")];
char typebuf[TYPECLASSBUF]; char typebuf[TYPECLASSBUF];
int type, n; unsigned int type;
int n;
isc_dir_t dir; isc_dir_t dir;
if (!start_directory(dirbuf, &dir)) { if (!start_directory(dirbuf, &dir)) {
@@ -482,16 +484,23 @@ sd(int rdclass, const char *classbuf, const char *dirbuf, char filetype) {
if (sscanf(dir.filename, TYPECLASSFMT, typebuf, &type) != 2) { if (sscanf(dir.filename, TYPECLASSFMT, typebuf, &type) != 2) {
continue; continue;
} }
if ((type > 65535) || (type < 0)) {
continue;
}
n = snprintf(buf, sizeof(buf), "%s_%d.%c", typebuf, type, /*
* sscanf accepts leading sign and zeros before type so
* compare the scanned items against the filename. Filter
* out mismatches. Also filter out bad file extensions.
*/
n = snprintf(buf, sizeof(buf), "%s_%u.%c", typebuf, type,
filetype); filetype);
INSIST(n > 0 && (unsigned)n < sizeof(buf)); INSIST(n > 0 && (unsigned)n < sizeof(buf));
if (strcmp(buf, dir.filename) != 0) { if (strcmp(buf, dir.filename) != 0) {
continue; continue;
} }
if (type > 65535) {
fprintf(stderr, "Error: type value > 65535 (%s)\n",
dir.filename);
exit(1);
}
add(rdclass, classbuf, type, typebuf, dirbuf); add(rdclass, classbuf, type, typebuf, dirbuf);
} }
@@ -518,7 +527,7 @@ int
main(int argc, char **argv) { main(int argc, char **argv) {
char buf[PATH_MAX]; char buf[PATH_MAX];
char srcdir[PATH_MAX]; char srcdir[PATH_MAX];
int rdclass; unsigned int rdclass;
char classbuf[TYPECLASSBUF]; char classbuf[TYPECLASSBUF];
struct tt *tt; struct tt *tt;
struct cc *cc; struct cc *cc;
@@ -622,16 +631,23 @@ main(int argc, char **argv) {
{ {
continue; continue;
} }
if ((rdclass > 65535) || (rdclass < 0)) {
continue;
}
n = snprintf(buf, sizeof(buf), "%srdata/%s_%d", srcdir, /*
* sscanf accepts leading sign and zeros before type so
* compare the scanned items against the filename. Filter
* out mismatches.
*/
n = snprintf(buf, sizeof(buf), "%srdata/%s_%u", srcdir,
classbuf, rdclass); classbuf, rdclass);
INSIST(n > 0 && (unsigned)n < sizeof(buf)); INSIST(n > 0 && (unsigned)n < sizeof(buf));
if (strcmp(buf + 6 + strlen(srcdir), dir.filename) != 0) { if (strcmp(buf + 6 + strlen(srcdir), dir.filename) != 0) {
continue; continue;
} }
if (rdclass > 65535) {
fprintf(stderr, "Error: class value > 65535 (%s)\n",
dir.filename);
exit(1);
}
sd(rdclass, classbuf, buf, filetype); sd(rdclass, classbuf, buf, filetype);
} }
end_directory(&dir); end_directory(&dir);