]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
resolved: generalize DNS RR type validity checks
authorLennart Poettering <lennart@poettering.net>
Thu, 10 Dec 2015 14:01:04 +0000 (15:01 +0100)
committerLennart Poettering <lennart@poettering.net>
Fri, 11 Dec 2015 13:14:27 +0000 (14:14 +0100)
Check the validity of RR types as we parse or receive data from IPC
clients, and use the same code for all of them.

src/resolve/dns-type.c
src/resolve/dns-type.h
src/resolve/resolved-bus.c
src/resolve/resolved-dns-packet.c
src/resolve/resolved-dns-transaction.c

index 8ce8a566f1db5f83c4304b13ff8f2bfd5891803f..8281da3b7c9bc6c79bb20ffea48e1ae7a4bd956e 100644 (file)
@@ -63,3 +63,25 @@ bool dns_type_is_pseudo(uint16_t type) {
                       DNS_TYPE_TKEY
         );
 }
+
+bool dns_type_is_valid_query(uint16_t type) {
+
+        /* The types valid as questions in packets */
+
+        return !IN_SET(type,
+                       0,
+                       DNS_TYPE_OPT,
+                       DNS_TYPE_TSIG,
+                       DNS_TYPE_TKEY);
+}
+
+bool dns_type_is_valid_rr(uint16_t type) {
+
+        /* The types valid as RR in packets (but not necessarily
+         * stored on servers). */
+
+        return !IN_SET(type,
+                       DNS_TYPE_ANY,
+                       DNS_TYPE_AXFR,
+                       DNS_TYPE_IXFR);
+}
index 2868025ad713dcbf5fcdfdb0f80e9ec410640b0e..038a0d0e54605b4dcbbe90cdf92339593b653089 100644 (file)
 
 const char *dns_type_to_string(int type);
 int dns_type_from_string(const char *s);
-bool dns_type_is_pseudo(uint16_t n);
+
+bool dns_type_is_pseudo(uint16_t type);
+bool dns_type_is_valid_query(uint16_t type);
+bool dns_type_is_valid_rr(uint16_t type);
 
 /* DNS record types, taken from
  * http://www.iana.org/assignments/dns-parameters/dns-parameters.xhtml.
index 1427638233efa6c279fc7402fa1d142a0d325dc9..c8c0d3d9b8a45e116e83f8685b22198083fdd34a 100644 (file)
@@ -553,6 +553,9 @@ static int bus_method_resolve_record(sd_bus_message *message, void *userdata, sd
         if (r == 0)
                 return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid name '%s'", name);
 
+        if (!dns_type_is_valid_query(type))
+                return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid RR type for query %" PRIu16, type);
+
         r = check_ifindex_flags(ifindex, &flags, 0, error);
         if (r < 0)
                 return r;
index 7c5be538b8f8e089e6f0d8a64dcdebc2128f49d8..4e069ab4cb45f4c8462d4fad2d0dd9e4beb5c372 100644 (file)
@@ -1525,9 +1525,7 @@ int dns_packet_read_rr(DnsPacket *p, DnsResourceRecord **ret, size_t *start) {
                 goto fail;
 
         if (key->class == DNS_CLASS_ANY ||
-            key->type == DNS_TYPE_ANY ||
-            key->type == DNS_TYPE_AXFR ||
-            key->type == DNS_TYPE_IXFR) {
+            !dns_type_is_valid_rr(key->type)) {
                 r = -EBADMSG;
                 goto fail;
         }
@@ -1971,6 +1969,11 @@ int dns_packet_extract(DnsPacket *p) {
                         if (r < 0)
                                 goto finish;
 
+                        if (!dns_type_is_valid_query(key->type)) {
+                                r = -EBADMSG;
+                                goto finish;
+                        }
+
                         r = dns_question_add(question, key);
                         if (r < 0)
                                 goto finish;
index bcf6d5c8100f10498aa5b8dae102086a5f4f0f0f..5cd03bc01da25448924e3cd5d3fec9291e72a18f 100644 (file)
@@ -107,11 +107,11 @@ int dns_transaction_new(DnsTransaction **ret, DnsScope *s, DnsResourceKey *key)
         assert(key);
 
         /* Don't allow looking up invalid or pseudo RRs */
-        if (IN_SET(key->type, DNS_TYPE_OPT, 0, DNS_TYPE_TSIG, DNS_TYPE_TKEY))
+        if (!dns_type_is_valid_query(key->type))
                 return -EINVAL;
 
         /* We only support the IN class */
-        if (key->class != DNS_CLASS_IN)
+        if (key->class != DNS_CLASS_IN && key->class != DNS_CLASS_ANY)
                 return -EOPNOTSUPP;
 
         r = hashmap_ensure_allocated(&s->manager->dns_transactions, NULL);