Commit Diff
Diff:
495bff70449b9a4bd0eda8407752867390116181
37727ad5f8d4b4d1b14a857b191b100b4b562e3b
Commit:
37727ad5f8d4b4d1b14a857b191b100b4b562e3b
Tree:
1c3e6c1be88c54e8cb307c168ef3d745b0656c97
Author:
pjp <pjp@delphinusdns.org>
Committer:
pjp <pjp@delphinusdns.org>
Date:
Sun Jul 19 13:50:06 2020 UTC
Message:
only allow classes through that we know in our parse, move this up early so that this parsing isn't failing deep down. Adjust dddctl query to allow other classes to be queried (with -c). Thanks to an annoying stranger or program that seems to want to go deep into my DNS stack before failing.
blob - 49ee60548f6c8ced1cdb27d5919f2209096b7789
blob + 58b9200d0db65619d864763b513a35ddb0a37774
--- query.c
+++ query.c
@@ -27,7 +27,7 @@
*/
/*
- * $Id: query.c,v 1.8 2020/07/16 17:54:03 pjp Exp $
+ * $Id: query.c,v 1.9 2020/07/19 13:50:06 pjp Exp $
*/
#include <sys/types.h>
@@ -87,7 +87,7 @@ int bytes_received;
int dig(int argc, char *argv[]);
int command_socket(char *);
int connect_server(char *, int, u_int32_t);
-int lookup_name(FILE *, int, char *, u_int16_t, struct soa *, u_int32_t, char *, u_int16_t, int *, int*);
+int lookup_name(FILE *, int, char *, u_int16_t, struct soa *, u_int32_t, char *, u_int16_t, int *, int*, uint16_t);
int notglue(ddDB *, struct rbtree *, char *);
@@ -212,14 +212,18 @@ dig(int argc, char *argv[])
char *yopt, *tsigpass = NULL, *tsigkey = NULL;
u_int32_t format = 0;
u_int16_t port = 53;
+ uint16_t class = DNS_CLASS_IN;
int ch, so, ms;
int type = DNS_TYPE_A;
int segment = 0;
int answers = 0;
int additionalcount = 0;
- while ((ch = getopt(argc, argv, "@:DIP:TZp:Q:y:")) != -1) {
+ while ((ch = getopt(argc, argv, "c:@:DIP:TZp:Q:y:")) != -1) {
switch (ch) {
+ case 'c':
+ class = atoi(optarg);
+ break;
case '@':
case 'Q':
nameserver = optarg;
@@ -339,7 +343,7 @@ dig(int argc, char *argv[])
}
} else {
- if (lookup_name(f, so, domainname, type, &mysoa, format, nameserver, port, &answers, &additionalcount) < 0) {
+ if (lookup_name(f, so, domainname, type, &mysoa, format, nameserver, port, &answers, &additionalcount, class) < 0) {
/* XXX maybe a packet dump here? */
exit(1);
}
@@ -421,7 +425,7 @@ connect_server(char *nameserver, int port, u_int32_t f
}
int
-lookup_name(FILE *f, int so, char *zonename, u_int16_t myrrtype, struct soa *mysoa, u_int32_t format, char *nameserver, u_int16_t port, int *answers, int *additionalcount)
+lookup_name(FILE *f, int so, char *zonename, u_int16_t myrrtype, struct soa *mysoa, u_int32_t format, char *nameserver, u_int16_t port, int *answers, int *additionalcount, uint16_t qclass)
{
int len, i, tmp32;
int numansw, numaddi, numauth;
@@ -494,7 +498,7 @@ lookup_name(FILE *f, int so, char *zonename, u_int16_t
pack16(&query[totallen], type);
totallen += sizeof(u_int16_t);
- class = htons(DNS_CLASS_IN);
+ class = htons(qclass);
pack16(&query[totallen], class);
totallen += sizeof(u_int16_t);
@@ -581,7 +585,7 @@ lookup_name(FILE *f, int so, char *zonename, u_int16_t
exit(1);
}
- ret = lookup_name(f, so, zonename, myrrtype, mysoa, format, nameserver, port, answers, additionalcount);
+ ret = lookup_name(f, so, zonename, myrrtype, mysoa, format, nameserver, port, answers, additionalcount, qclass);
close(so);
return (ret);
}
blob - f8b27ce711674eb4142dc4c2065a066f4f309c3a
blob + 77734a4765acb6a3d8738086e496b3211a77b5a7
--- util.c
+++ util.c
@@ -27,7 +27,7 @@
*/
/*
- * $Id: util.c,v 1.74 2020/07/19 08:02:13 pjp Exp $
+ * $Id: util.c,v 1.75 2020/07/19 13:50:06 pjp Exp $
*/
#include <sys/types.h>
@@ -980,7 +980,23 @@ build_question(char *buf, int len, int additional, cha
dolog(LOG_INFO, "question rr is truncated\n");
return NULL;
}
-
+ /* check the class type so that $IP is erroring earlier */
+
+ o = (end_name + sizeof(uint16_t));
+ qclass = ntohs(unpack16(o));
+
+ switch (qclass) {
+ case DNS_CLASS_ANY:
+ case DNS_CLASS_NONE:
+ case DNS_CLASS_HS:
+ case DNS_CLASS_CH:
+ case DNS_CLASS_IN:
+ break;
+ default:
+ dolog(LOG_INFO, "unsupported class %d\n", qclass);
+ return NULL;
+ break;
+ }
q = (void *)calloc(1, sizeof(struct question));
if (q == NULL) {
repomaster@centroid.eu