]> The Tcpdump Group git mirrors - tcpdump/blobdiff - print-dhcp6.c
More UNALIGNED_MEM{CPY,CMP} on IP addresses.
[tcpdump] / print-dhcp6.c
index b317eb4eb94ecda9bba03f334030fa46aaa585d5..8a119ff5fb82e1297a5d84d7762a13d77ff3911b 100644 (file)
@@ -28,7 +28,7 @@
  */
 /*
  * RFC3315: DHCPv6
- * supported DHCPv6 options: 
+ * supported DHCPv6 options:
  *  RFC3319: Session Initiation Protocol (SIP) Servers options,
  *  RFC3633: IPv6 Prefix options,
  *  RFC3646: DNS Configuration options,
  *  RFC6334: Dual-Stack Lite option,
  */
 
-#ifndef lint
-static const char rcsid[] _U_ =
-    "@(#) $Header: /tcpdump/master/tcpdump/print-dhcp6.c,v 1.37 2008-02-06 10:26:09 guy Exp $";
-#endif
-
 #ifdef HAVE_CONFIG_H
 #include "config.h"
 #endif
@@ -59,7 +54,7 @@ static const char rcsid[] _U_ =
 #include "extract.h"
 
 /* lease duration */
-#define DHCP6_DURATITION_INFINITE 0xffffffff
+#define DHCP6_DURATION_INFINITE 0xffffffff
 
 /* Error Values */
 #define DH6ERR_FAILURE         16
@@ -147,8 +142,8 @@ struct dhcp6_relay {
 #define DH6OPT_RECONF_ACCEPT 20
 #define DH6OPT_SIP_SERVER_D 21
 #define DH6OPT_SIP_SERVER_A 22
-#define DH6OPT_DNS 23
-#define DH6OPT_DNSNAME 24
+#define DH6OPT_DNS_SERVERS 23
+#define DH6OPT_DOMAIN_LIST 24
 #define DH6OPT_IA_PD 25
 #define DH6OPT_IA_PD_PREFIX 26
 #define DH6OPT_NIS_SERVERS 27
@@ -235,9 +230,9 @@ dhcp6opt_name(int type)
                return "SIP-servers-domain";
        case DH6OPT_SIP_SERVER_A:
                return "SIP-servers-address";
-       case DH6OPT_DNS:
+       case DH6OPT_DNS_SERVERS:
                return "DNS-server";
-       case DH6OPT_DNSNAME:
+       case DH6OPT_DOMAIN_LIST:
                return "DNS-search-list";
        case DH6OPT_IA_PD:
                return "IA_PD";
@@ -335,7 +330,7 @@ dhcp6stcode(int code)
 static void
 dhcp6opt_print(const u_char *cp, const u_char *ep)
 {
-       struct dhcp6opt *dh6o;
+       const struct dhcp6opt *dh6o;
        const u_char *tp;
        size_t i;
        u_int16_t opttype;
@@ -589,7 +584,7 @@ dhcp6opt_print(const u_char *cp, const u_char *ep)
                        printf(")");
                        break;
                case DH6OPT_SIP_SERVER_A:
-               case DH6OPT_DNS:
+               case DH6OPT_DNS_SERVERS:
                case DH6OPT_SNTP_SERVERS:
                case DH6OPT_NIS_SERVERS:
                case DH6OPT_NISP_SERVERS:
@@ -606,12 +601,14 @@ dhcp6opt_print(const u_char *cp, const u_char *ep)
                        printf(")");
                        break;
                case DH6OPT_SIP_SERVER_D:
+               case DH6OPT_DOMAIN_LIST:
                        tp = (u_char *)(dh6o + 1);
-                       while (tp < ep) {
+                       while (tp < cp + sizeof(*dh6o) + optlen) {
                                putchar(' ');
-                               if((tp = ns_nprint(tp, ep)) == NULL)
+                               if ((tp = ns_nprint(tp, cp + sizeof(*dh6o) + optlen)) == NULL)
                                        goto trunc;
                        }
+                       printf(")");
                        break;
                case DH6OPT_STATUS_CODE:
                        if (optlen < 2) {
@@ -742,11 +739,13 @@ dhcp6opt_print(const u_char *cp, const u_char *ep)
                                break;
                        }
                        tp = (u_char *)(dh6o + 1);
-                       while (tp < ep - 4) {
+                       while (tp < cp + sizeof(*dh6o) + optlen - 4) {
                                subopt_code = EXTRACT_16BITS(tp);
                                tp += 2;
                                subopt_len = EXTRACT_16BITS(tp);
                                tp += 2;
+                               if (tp + subopt_len > cp + sizeof(*dh6o) + optlen)
+                                       goto trunc;
                                printf(" subopt:%d", subopt_code);
                                switch (subopt_code) {
                                case DH6OPT_NTP_SUBOPTION_SRV_ADDR:
@@ -756,17 +755,17 @@ dhcp6opt_print(const u_char *cp, const u_char *ep)
                                                break;
                                        }
                                        printf(" %s", ip6addr_string(&tp[0]));
-                                       tp += subopt_len;
                                        break;
                                case DH6OPT_NTP_SUBOPTION_SRV_FQDN:
                                        putchar(' ');
-                                       ns_nprint(tp, ep);
-                                       tp += subopt_len;
+                                       if (ns_nprint(tp, tp + subopt_len) == NULL)
+                                               goto trunc;
                                        break;
                                default:
                                        printf(" ?");
                                        break;
                                }
+                               tp += subopt_len;
                        }
                        printf(")");
                        break;