Skip to content

Commit

Permalink
detect duplicate or overrun in rrtype sets (PR #194) (#195)
Browse files Browse the repository at this point in the history
* Version 2.6.0.  
* detect duplicate or overrun in rrtype sets (PR #194)
* Document MAX_FETCHES variable

Primary-authored-by: paul vixie <[email protected]>
Slight-coauthored-by: David Waitzman <[email protected]>
  • Loading branch information
vixie authored Oct 29, 2021
1 parent d5f19ea commit cbd4e44
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 11 deletions.
5 changes: 5 additions & 0 deletions defs.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,12 @@
#error "No passive DNS system defined"
#endif
#define DEFAULT_VERB 0

/* maximum number of concurrent fetches.
* must not be greater than any pDNS system's concurrent connection limit.
*/
#define MAX_FETCHES 8

#define DNSDBQ_SYSTEM "DNSDBQ_SYSTEM"

#define CREATE(p, s) if ((p) != NULL) { my_panic(false, "non-NULL ptr"); } \
Expand Down
39 changes: 29 additions & 10 deletions dnsdbq.c
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ static const char *batch_options(const char *, qparam_t, qparam_ct);
static const char *batch_parse(char *, qdesc_t);
static char *makepath(qdesc_ct);
static query_t query_launcher(qdesc_ct, qparam_ct, writer_t);
static const char *multitype_coherency(const char *);
static const char *rrtype_correctness(const char *);
static void launch_fetch(query_t, const char *, pdns_fence_ct);
static void ruminate_json(int, qparam_ct);
static const char *lookup_ok(void);
Expand Down Expand Up @@ -1390,8 +1390,8 @@ query_launcher(qdesc_ct qdp, qparam_ct qpp, writer_t writer) {
char *path = makepath(qdp);
launch_fetch(query, path, &fence);
DESTROY(path);
} else if ((msg = multitype_coherency(qdp->rrtype)) != NULL) {
fprintf(stderr, "%s: multitype_coherency failed: %s\n",
} else if ((msg = rrtype_correctness(qdp->rrtype)) != NULL) {
fprintf(stderr, "%s: rrtype incorrect: %s\n",
program_name, msg);
DESTROY(query);
return NULL;
Expand Down Expand Up @@ -1432,12 +1432,15 @@ query_launcher(qdesc_ct qdp, qparam_ct qpp, writer_t writer) {
return query;
}

/* multitype_coherency -- return an error text if these rrtypes don't mix.
/* rrtype_correctness -- return an error text if the rrtypes are senseless
*/
static const char *
multitype_coherency(const char *input) {
rrtype_correctness(const char *input) {
char **rrtypeset = calloc(MAX_FETCHES, sizeof(char *));
char *rrtypes = strdup(input);
char *saveptr = NULL;
const char *ret = NULL;
int nrrtypeset = 0;
bool some = false, any = false,
some_dnssec = false, any_dnssec = false;
for (char *rrtype = strtok_r(rrtypes, ",", &saveptr);
Expand All @@ -1447,6 +1450,16 @@ multitype_coherency(const char *input) {
for (char *p = rrtype; *p != '\0'; p++)
if (isupper(*p))
*p = (char) tolower(*p);
if (nrrtypeset == MAX_FETCHES) {
ret = "too many rrtypes specified";
goto done;
}
for (int i = 0; i < nrrtypeset; i++)
if (strcmp(rrtype, rrtypeset[i]) == 0) {
ret = "duplicate rrtype encountered";
goto done;
}
rrtypeset[nrrtypeset++] = rrtype;
if (strcmp(rrtype, "any") == 0)
any = true;
else if (strcmp(rrtype, "any-dnssec") == 0)
Expand All @@ -1464,13 +1477,19 @@ multitype_coherency(const char *input) {
some_dnssec = true;
else
some = true;
if (any && some)
return "ANY is redundant when mixed like this";
if (any_dnssec && some_dnssec)
return "ANY-DNSSEC is redundant when mixed like this";
if (any && some) {
ret = "ANY is redundant when mixed like this";
goto done;
}
if (any_dnssec && some_dnssec) {
ret = "ANY-DNSSEC is redundant when mixed like this";
goto done;
}
}
done:
DESTROY(rrtypes);
return NULL;
DESTROY(rrtypeset);
return ret;
}

/* launch_fetch -- actually launch a query job, given a path and time fences.
Expand Down
2 changes: 1 addition & 1 deletion globals.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ extern const struct verb verbs[];
#endif

EXTERN const char id_swclient[] INIT("dnsdbq");
EXTERN const char id_version[] INIT("2.5.7");
EXTERN const char id_version[] INIT("2.6.0");
EXTERN const char *program_name INIT(NULL);
EXTERN const char path_sort[] INIT("/usr/bin/sort");
EXTERN const char json_header[] INIT("Accept: application/json");
Expand Down

0 comments on commit cbd4e44

Please sign in to comment.