]> The Tcpdump Group git mirrors - tcpdump/blobdiff - print-domain.c
CHANGES: Add/move change(s) backported to 4.99
[tcpdump] / print-domain.c
index dcfc9fd21c98b979b488ada95c3dda866c4e0f84..08d8460a4995894902ef4db994dbf61d1ea3d720 100644 (file)
@@ -21,9 +21,7 @@
 
 /* \summary: Domain Name System (DNS) printer */
 
-#ifdef HAVE_CONFIG_H
 #include <config.h>
-#endif
 
 #include "netdissect-stdinc.h"
 
@@ -517,13 +515,13 @@ const struct tok ns_type2str[] = {
        { T_CERT,       "CERT" },               /* RFC 4398 */
        { T_A6,         "A6" },                 /* RFC 6563 */
        { T_DNAME,      "DNAME" },              /* RFC 6672 */
-       { T_SINK,       "SINK" },
+       { T_SINK,       "SINK" },
        { T_OPT,        "OPT" },                /* RFC 6891 */
-       { T_APL,        "APL" },                /* RFC 3123 */
+       { T_APL,        "APL" },                /* RFC 3123 */
        { T_DS,         "DS" },                 /* RFC 4034 */
        { T_SSHFP,      "SSHFP" },              /* RFC 4255 */
        { T_IPSECKEY,   "IPSECKEY" },           /* RFC 4025 */
-       { T_RRSIG,      "RRSIG" },              /* RFC 4034 */
+       { T_RRSIG,      "RRSIG" },              /* RFC 4034 */
        { T_NSEC,       "NSEC" },               /* RFC 4034 */
        { T_DNSKEY,     "DNSKEY" },             /* RFC 4034 */
        { T_DHCID,      "DHCID" },              /* RFC 4071 */
@@ -724,11 +722,10 @@ ns_rprint(netdissect_options *ndo,
        len = GET_BE_U_2(cp);
        cp += 2;
 
-       rp = cp + len;
-
        ND_PRINT(" %s", tok2str(ns_type2str, "Type%u", typ));
-       if (rp > ndo->ndo_snapend)
-               return(NULL);
+
+       ND_TCHECK_LEN(cp, len);
+       rp = cp + len;
 
        switch (typ) {
        case T_A:
@@ -839,6 +836,10 @@ ns_rprint(netdissect_options *ndo,
        case T_URI:
                if (!ND_TTEST_LEN(cp, len))
                        return(NULL);
+               if (len < 4) {
+                       ND_PRINT(" len %u is too short (< 4)", len);
+                       break;
+               }
                ND_PRINT(" %u %u ", GET_BE_U_2(cp), GET_BE_U_2(cp + 2));
                if (nd_printn(ndo, cp + 4, len - 4, ndo->ndo_snapend))
                        return(NULL);
@@ -894,6 +895,9 @@ ns_rprint(netdissect_options *ndo,
            }
        }
        return (rp);            /* XXX This isn't always right */
+
+trunc:
+       return(NULL);
 }
 
 void
@@ -1070,8 +1074,7 @@ domain_print(netdissect_options *ndo,
                        if (arcount)
                                goto trunc;
                }
-       }
-       else {
+       } else {
                /* this is a request */
                ND_PRINT("%u%s%s%s", GET_BE_U_2(np->id),
                          ns_ops[DNS_OPCODE(flags)],
@@ -1088,8 +1091,7 @@ domain_print(netdissect_options *ndo,
                                ND_PRINT(" [%uq]", qdcount);
                        if (ancount != 1)
                                ND_PRINT(" [%ua]", ancount);
-               }
-               else {
+               } else {
                        if (ancount)
                                ND_PRINT(" [%ua]", ancount);
                        if (qdcount != 1)