From a25211918f2e790c67d859d20ccf8dbb81da1598 Mon Sep 17 00:00:00 2001
From: Guy Harris <guy@alum.mit.edu>
Date: Sun, 19 Feb 2017 21:13:25 -0800
Subject: [PATCH] CVE-2017-13003/Clean up the LMP dissector.
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Do a lot more bounds and length checks.

Add a EXTRACT_8BITS() macro, for completeness, and so as not to confuse
people into thinking that, to fetch a 1-byte value from a packet, they
need to use EXTRACT_16BITS() to fetch a 2-byte value and then use
shifting and masking to extract the desired byte.  Use that rather than
using EXTRACT_16BITS() to fetch a 2-byte value and then shifting and
masking to extract the desired byte.

Don't treat IPv4 addresses and unnumbered interface IDs the same; the
first should be printed as an IPv4 address but the latter should just be
printed as numbers.  Handle IPv6 addresses in more object types while
we're at it.

This fixes a buffer over-read discovered by Forcepoint's security
researchers Otto Airamo & Antti Levomäki.

Add a test using the capture file supplied by the reporter(s).
---
 extract.h                 |   8 +-
 print-lmp.c               | 432 ++++++++++++++++++++++++++++++--------
 tests/TESTLIST            |   1 +
 tests/lmpv1_busyloop.out  |  42 ++++
 tests/lmpv1_busyloop.pcap | Bin 0 -> 765 bytes
 5 files changed, 400 insertions(+), 83 deletions(-)
 create mode 100644 tests/lmpv1_busyloop.out
 create mode 100644 tests/lmpv1_busyloop.pcap

Index: tcpdump-3.9.8/extract.h
===================================================================
--- tcpdump-3.9.8.orig/extract.h
+++ tcpdump-3.9.8/extract.h
@@ -22,6 +22,13 @@
  */
 
 /*
+ * For 8-bit values; provided for the sake of completeness.  Byte order
+ * isn't relevant, and alignment isn't an issue.
+ */
+#define EXTRACT_8BITS(p)	(*(p))
+#define EXTRACT_LE_8BITS(p)	(*(p))
+
+/*
  * Macros to extract possibly-unaligned big-endian integral values.
  */
 #ifdef LBL_ALIGN
@@ -106,7 +113,6 @@ typedef struct {
  * Macros to extract possibly-unaligned little-endian integral values.
  * XXX - do loads on little-endian machines that support unaligned loads?
  */
-#define EXTRACT_LE_8BITS(p) (*(p))
 #define EXTRACT_LE_16BITS(p) \
 	((u_int16_t)((u_int16_t)*((const u_int8_t *)(p) + 1) << 8 | \
 		     (u_int16_t)*((const u_int8_t *)(p) + 0)))
Index: tcpdump-3.9.8/print-lmp.c
===================================================================
--- tcpdump-3.9.8.orig/print-lmp.c
+++ tcpdump-3.9.8/print-lmp.c
@@ -358,16 +358,83 @@ static const struct tok lmp_ctype_values
     { 0, NULL}
 };
 
+static int
+lmp_print_data_link_subobjs(const u_char *obj_tptr,
+                            int total_subobj_len, int offset)
+{
+    int hexdump = FALSE;
+    int subobj_type, subobj_len;
+
+    union { /* int to float conversion buffer */
+        float f;
+        uint32_t i;
+    } bw;
+
+    while (total_subobj_len > 0 && hexdump == FALSE ) {
+	subobj_type = EXTRACT_8BITS(obj_tptr+offset);
+	subobj_len  = EXTRACT_8BITS(obj_tptr+offset+1);
+	printf("\n\t    Subobject, Type: %s (%u), Length: %u",
+		tok2str(lmp_data_link_subobj,
+			"Unknown",
+			subobj_type),
+			subobj_type,
+			subobj_len);
+	if (subobj_len < 4) {
+	    printf(" (too short)");
+	    break;
+	}
+	if ((subobj_len % 4) != 0) {
+	    printf(" (not a multiple of 4)");
+	    break;
+	}
+	if (total_subobj_len < subobj_len) {
+	    printf(" (goes past the end of the object)");
+	    break;
+	}
+	switch(subobj_type) {
+	case INT_SWITCHING_TYPE_SUBOBJ:
+	    printf("\n\t      Switching Type: %s (%u)",
+		tok2str(gmpls_switch_cap_values,
+			"Unknown",
+			EXTRACT_8BITS(obj_tptr+offset+2)),
+		EXTRACT_8BITS(obj_tptr+offset+2));
+	    printf("\n\t      Encoding Type: %s (%u)",
+		tok2str(gmpls_encoding_values,
+			"Unknown",
+			EXTRACT_8BITS(obj_tptr+offset+3)),
+		EXTRACT_8BITS(obj_tptr+offset+3));
+	    bw.i = EXTRACT_32BITS(obj_tptr+offset+4);
+	    printf("\n\t      Min Reservable Bandwidth: %.3f Mbps",
+                bw.f*8/1000000);
+	    bw.i = EXTRACT_32BITS(obj_tptr+offset+8);
+	    printf("\n\t      Max Reservable Bandwidth: %.3f Mbps",
+                bw.f*8/1000000);
+	    break;
+	case WAVELENGTH_SUBOBJ:
+	    printf("\n\t      Wavelength: %u",
+		EXTRACT_32BITS(obj_tptr+offset+4));
+	    break;
+	default:
+	    /* Any Unknown Subobject ==> Exit loop */
+	    hexdump=TRUE;
+	    break;
+	}
+	total_subobj_len-=subobj_len;
+	offset+=subobj_len;
+    }
+    return (hexdump);
+}
+
 void
 lmp_print(register const u_char *pptr, register u_int len) {
 
     const struct lmp_common_header *lmp_com_header;
     const struct lmp_object_header *lmp_obj_header;
     const u_char *tptr,*obj_tptr;
-    int tlen,lmp_obj_len,lmp_obj_ctype,obj_tlen;
+    u_int tlen,lmp_obj_len,lmp_obj_ctype,obj_tlen;
     int hexdump;
-    int offset,subobj_type,subobj_len,total_subobj_len;
-    int link_type;
+    u_int offset;
+    u_int link_type;
 
     union { /* int to float conversion buffer */
         float f; 
@@ -406,6 +473,15 @@ lmp_print(register const u_char *pptr, r
            bittok2str(lmp_header_flag_values,"none",lmp_com_header->flags),
            tlen);
 
+    if (tlen < sizeof(const struct lmp_common_header)) {
+	    printf(" (too short)");
+	    return;
+    }
+    if (tlen > len) {
+	    printf(" (too long)");
+	    tlen = len;
+    }
+
     tptr+=sizeof(const struct lmp_common_header);
     tlen-=sizeof(const struct lmp_common_header);
 
@@ -418,9 +494,6 @@ lmp_print(register const u_char *pptr, r
         lmp_obj_len=EXTRACT_16BITS(lmp_obj_header->length);
         lmp_obj_ctype=(lmp_obj_header->ctype)&0x7f;
 
-        if(lmp_obj_len % 4 || lmp_obj_len < 4)
-            return;
-
         printf("\n\t  %s Object (%u), Class-Type: %s (%u) Flags: [%snegotiable], length: %u",
                tok2str(lmp_obj_values,
                        "Unknown",
@@ -433,6 +506,15 @@ lmp_print(register const u_char *pptr, r
                (lmp_obj_header->ctype)&0x80 ? "" : "non-",
                lmp_obj_len);
 
+        if (lmp_obj_len < 4) {
+		printf(" (too short)");
+		return;
+        }
+        if ((lmp_obj_len % 4) != 0) {
+		printf(" (not a multiple of 4)");
+		return;
+        }
+
         obj_tptr=tptr+sizeof(struct lmp_object_header);
         obj_tlen=lmp_obj_len-sizeof(struct lmp_object_header);
 
@@ -447,6 +529,10 @@ lmp_print(register const u_char *pptr, r
             switch(lmp_obj_ctype) {
             case LMP_CTYPE_LOC:
             case LMP_CTYPE_RMT:
+		if (obj_tlen != 4) {
+			printf(" (not correct for object)");
+			break;
+                }
                 printf("\n\t    Control Channel ID: %u (0x%08x)",
                        EXTRACT_32BITS(obj_tptr),
                        EXTRACT_32BITS(obj_tptr));
@@ -462,6 +548,10 @@ lmp_print(register const u_char *pptr, r
             switch(lmp_obj_ctype) {
             case LMP_CTYPE_IPV4_LOC:
             case LMP_CTYPE_IPV4_RMT:
+		if (obj_tlen != 4) {
+			printf(" (not correct for object)");
+			break;
+                }
                 printf("\n\t    IPv4 Link ID: %s (0x%08x)",
                        ipaddr_string(obj_tptr),
                        EXTRACT_32BITS(obj_tptr));
@@ -469,6 +559,10 @@ lmp_print(register const u_char *pptr, r
 #ifdef INET6
             case LMP_CTYPE_IPV6_LOC:
             case LMP_CTYPE_IPV6_RMT:
+		if (obj_tlen != 16) {
+			printf(" (not correct for object)");
+			break;
+                }
                 printf("\n\t    IPv6 Link ID: %s (0x%08x)",
                        ip6addr_string(obj_tptr),
                        EXTRACT_32BITS(obj_tptr));
@@ -476,6 +570,10 @@ lmp_print(register const u_char *pptr, r
 #endif
             case LMP_CTYPE_UNMD_LOC:
             case LMP_CTYPE_UNMD_RMT:
+		if (obj_tlen != 4) {
+			printf(" (not correct for object)");
+			break;
+                }
                 printf("\n\t    Link ID: %u (0x%08x)",
                        EXTRACT_32BITS(obj_tptr),
                        EXTRACT_32BITS(obj_tptr));
@@ -488,11 +586,19 @@ lmp_print(register const u_char *pptr, r
         case LMP_OBJ_MESSAGE_ID:
             switch(lmp_obj_ctype) {
             case LMP_CTYPE_1:
+		if (obj_tlen != 4) {
+			printf(" (not correct for object)");
+			break;
+                }
                 printf("\n\t    Message ID: %u (0x%08x)",
                        EXTRACT_32BITS(obj_tptr),
                        EXTRACT_32BITS(obj_tptr));
                 break;
             case LMP_CTYPE_2:
+		if (obj_tlen != 4) {
+			printf(" (not correct for object)");
+			break;
+                }
                 printf("\n\t    Message ID Ack: %u (0x%08x)",
                        EXTRACT_32BITS(obj_tptr),
                        EXTRACT_32BITS(obj_tptr));
@@ -506,6 +612,10 @@ lmp_print(register const u_char *pptr, r
             switch(lmp_obj_ctype) {
             case LMP_CTYPE_LOC:
             case LMP_CTYPE_RMT:
+		if (obj_tlen != 4) {
+			printf(" (not correct for object)");
+			break;
+                }
                 printf("\n\t    Node ID: %s (0x%08x)",
                        ipaddr_string(obj_tptr),
                        EXTRACT_32BITS(obj_tptr));
@@ -519,6 +629,10 @@ lmp_print(register const u_char *pptr, r
         case LMP_OBJ_CONFIG:
             switch(lmp_obj_ctype) {
             case LMP_CTYPE_HELLO_CONFIG:
+		if (obj_tlen != 4) {
+			printf(" (not correct for object)");
+			break;
+                }
                 printf("\n\t    Hello Interval: %u\n\t    Hello Dead Interval: %u",
                        EXTRACT_16BITS(obj_tptr),
                        EXTRACT_16BITS(obj_tptr+2));
@@ -532,6 +646,10 @@ lmp_print(register const u_char *pptr, r
         case LMP_OBJ_HELLO:
             switch(lmp_obj_ctype) {
 	    case LMP_CTYPE_HELLO:
+		if (obj_tlen != 8) {
+			printf(" (not correct for object)");
+			break;
+                }
                 printf("\n\t    TxSeqNum: %u\n\t    RcvSeqNum: %u",
                        EXTRACT_32BITS(obj_tptr),
                        EXTRACT_32BITS(obj_tptr+4));
@@ -543,92 +661,128 @@ lmp_print(register const u_char *pptr, r
             break;      
 	    
         case LMP_OBJ_TE_LINK:
-		printf("\n\t    Flags: [%s]",
-		bittok2str(lmp_obj_te_link_flag_values,
-			"none",
-			EXTRACT_16BITS(obj_tptr)>>8));
-            
 	    switch(lmp_obj_ctype) {
-	    case LMP_CTYPE_IPV4:
-		printf("\n\t    Local Link-ID: %s (0x%08x) \
-			\n\t    Remote Link-ID: %s (0x%08x)",
-                       ipaddr_string(obj_tptr+4),
-                       EXTRACT_32BITS(obj_tptr+4),
-                       ipaddr_string(obj_tptr+8),
-                       EXTRACT_32BITS(obj_tptr+8));
+		case LMP_CTYPE_IPV4:
+			if (obj_tlen != 12) {
+				printf(" (not correct for object)");
+				break;
+			}
+			printf("\n\t    Flags: [%s]",
+			       bittok2str(lmp_obj_te_link_flag_values,
+					  "none",
+					  EXTRACT_8BITS(obj_tptr)));
+			printf("\n\t    Local Link-ID: %s (0x%08x)"
+			       "\n\t    Remote Link-ID: %s (0x%08x)",
+			       ipaddr_string(obj_tptr+4),
+			       EXTRACT_32BITS(obj_tptr+4),
+			       ipaddr_string(obj_tptr+8),
+			       EXTRACT_32BITS(obj_tptr+8));
 		break;
 		
 #ifdef INET6
-	    case LMP_CTYPE_IPV6:
+		case LMP_CTYPE_IPV6:
+			if (obj_tlen != 36) {
+				printf(" (not correct for object)");
+				break;
+			}
+			printf("\n\t    Flags: [%s]",
+			       bittok2str(lmp_obj_te_link_flag_values,
+					  "none",
+					  EXTRACT_8BITS(obj_tptr)));
+
+			printf("\n\t    Local Link-ID: %s (0x%08x)"
+			       "\n\t    Remote Link-ID: %s (0x%08x)",
+			       ip6addr_string(obj_tptr+4),
+			       EXTRACT_32BITS(obj_tptr+4),
+			       ip6addr_string(obj_tptr+20),
+			       EXTRACT_32BITS(obj_tptr+20));
+			break;
 #endif
-	    case LMP_CTYPE_UNMD:
-            default:
-                hexdump=TRUE;
-            }
-            break;
+		case LMP_CTYPE_UNMD:
+			if (obj_tlen != 12) {
+				printf(" (not correct for object)");
+				break;
+			}
+			printf("\n\t    Flags: [%s]",
+			       bittok2str(lmp_obj_te_link_flag_values,
+					  "none",
+					  EXTRACT_8BITS(obj_tptr)));
+
+			printf("\n\t    Local Link-ID: %u (0x%08x)"
+			       "\n\t    Remote Link-ID: %u (0x%08x)",
+			       EXTRACT_32BITS(obj_tptr+4),
+			       EXTRACT_32BITS(obj_tptr+4),
+			       EXTRACT_32BITS(obj_tptr+8),
+			       EXTRACT_32BITS(obj_tptr+8));
+			break;
+
+		default:
+			hexdump=TRUE;
+	    }
+	    break;
 	
         case LMP_OBJ_DATA_LINK:
-		printf("\n\t    Flags: [%s]",
-		bittok2str(lmp_obj_data_link_flag_values,
-			"none",
-			EXTRACT_16BITS(obj_tptr)>>8));
-            
 	    switch(lmp_obj_ctype) {
 	    case LMP_CTYPE_IPV4:
-	    case LMP_CTYPE_UNMD:
+		if (obj_tlen < 12) {
+			printf(" (not correct for object)");
+			break;
+                }
+	        printf("\n\t    Flags: [%s]",
+		       bittok2str(lmp_obj_data_link_flag_values,
+				  "none",
+				  EXTRACT_8BITS(obj_tptr)));
                 printf("\n\t    Local Interface ID: %s (0x%08x) \
 			\n\t    Remote Interface ID: %s (0x%08x)",
                        ipaddr_string(obj_tptr+4),
                        EXTRACT_32BITS(obj_tptr+4),
                        ipaddr_string(obj_tptr+8),
                        EXTRACT_32BITS(obj_tptr+8));
-		
-		total_subobj_len = lmp_obj_len - 16;	 
-		offset = 12;
-		while (total_subobj_len > 0 && hexdump == FALSE ) {
-			subobj_type = EXTRACT_16BITS(obj_tptr+offset)>>8;
-			subobj_len  = EXTRACT_16BITS(obj_tptr+offset)&0x00FF;
-			printf("\n\t    Subobject, Type: %s (%u), Length: %u",
-				tok2str(lmp_data_link_subobj,
-					"Unknown",
-					subobj_type),
-					subobj_type,
-					subobj_len);
-			switch(subobj_type) {
-			case INT_SWITCHING_TYPE_SUBOBJ:
-				printf("\n\t      Switching Type: %s (%u)",
-					tok2str(gmpls_switch_cap_values, 
-						"Unknown", 
-						EXTRACT_16BITS(obj_tptr+offset+2)>>8),
-					EXTRACT_16BITS(obj_tptr+offset+2)>>8);
-				printf("\n\t      Encoding Type: %s (%u)",
-					tok2str(gmpls_encoding_values, 
-						"Unknown", 
-						EXTRACT_16BITS(obj_tptr+offset+2)&0x00FF),
-					EXTRACT_16BITS(obj_tptr+offset+2)&0x00FF);
-				bw.i = EXTRACT_32BITS(obj_tptr+offset+4);
-				printf("\n\t      Min Reservable Bandwidth: %.3f Mbps",
-                                       bw.f*8/1000000);
-				bw.i = EXTRACT_32BITS(obj_tptr+offset+8);
-				printf("\n\t      Max Reservable Bandwidth: %.3f Mbps",
-                                       bw.f*8/1000000);
-				break;	
-			case WAVELENGTH_SUBOBJ:
-				printf("\n\t      Wavelength: %u",
-					EXTRACT_32BITS(obj_tptr+offset+4));
-				break;
-			default:
-				/* Any Unknown Subobject ==> Exit loop */
-				hexdump=TRUE;
-				break;
-			}
-			total_subobj_len-=subobj_len;
-			offset+=subobj_len;
-		}
-		
+
+		if (lmp_print_data_link_subobjs(obj_tptr, obj_tlen - 12, 12))
+			hexdump=TRUE;
 		break;
+
 #ifdef INET6   
 	    case LMP_CTYPE_IPV6:
+		if (obj_tlen < 36) {
+			printf(" (not correct for object)");
+			break;
+                }
+	        printf("\n\t    Flags: [%s]",
+		       bittok2str(lmp_obj_data_link_flag_values,
+				  "none",
+				  EXTRACT_8BITS(obj_tptr)));
+                printf("\n\t    Local Interface ID: %s (0x%08x)"
+                       "\n\t    Remote Interface ID: %s (0x%08x)",
+                       ip6addr_string(obj_tptr+4),
+                       EXTRACT_32BITS(obj_tptr+4),
+                       ip6addr_string(obj_tptr+20),
+                       EXTRACT_32BITS(obj_tptr+20));
+
+		if (lmp_print_data_link_subobjs(obj_tptr, obj_tlen - 36, 36))
+			hexdump=TRUE;
+		break;
+
+	    case LMP_CTYPE_UNMD:
+		if (obj_tlen < 12) {
+			printf(" (not correct for object)");
+			break;
+                }
+	        printf("\n\t    Flags: [%s]",
+		       bittok2str(lmp_obj_data_link_flag_values,
+				  "none",
+				  EXTRACT_8BITS(obj_tptr)));
+                printf("\n\t    Local Interface ID: %u (0x%08x)"
+                       "\n\t    Remote Interface ID: %u (0x%08x)",
+                       EXTRACT_32BITS(obj_tptr+4),
+                       EXTRACT_32BITS(obj_tptr+4),
+                       EXTRACT_32BITS(obj_tptr+8),
+                       EXTRACT_32BITS(obj_tptr+8));
+
+		if (lmp_print_data_link_subobjs(obj_tptr, obj_tlen - 12, 12))
+			hexdump=TRUE;
+		break;
 #endif
             default:
                 hexdump=TRUE;
@@ -638,6 +792,10 @@ lmp_print(register const u_char *pptr, r
         case LMP_OBJ_VERIFY_BEGIN:
 	    switch(lmp_obj_ctype) {
             case LMP_CTYPE_1:
+		if (obj_tlen != 20) {
+			printf(" (not correct for object)");
+			break;
+                }
 		printf("\n\t    Flags: %s",
 		bittok2str(lmp_obj_begin_verify_flag_values,
 			"none",
@@ -666,6 +824,10 @@ lmp_print(register const u_char *pptr, r
         case LMP_OBJ_VERIFY_BEGIN_ACK:
 	    switch(lmp_obj_ctype) {
             case LMP_CTYPE_1:
+		if (obj_tlen != 4) {
+			printf(" (not correct for object)");
+			break;
+                }
                 printf("\n\t    Verify Dead Interval: %u 	\
 			\n\t    Verify Transport Response: %u",
                        EXTRACT_16BITS(obj_tptr),
@@ -680,6 +842,10 @@ lmp_print(register const u_char *pptr, r
 	case LMP_OBJ_VERIFY_ID:
 	    switch(lmp_obj_ctype) {
             case LMP_CTYPE_1:
+		if (obj_tlen != 4) {
+			printf(" (not correct for object)");
+			break;
+                }
                 printf("\n\t    Verify ID: %u",
                        EXTRACT_32BITS(obj_tptr));
                 break;
@@ -692,19 +858,20 @@ lmp_print(register const u_char *pptr, r
 	case LMP_OBJ_CHANNEL_STATUS:
             switch(lmp_obj_ctype) {
 	    case LMP_CTYPE_IPV4:
-	    case LMP_CTYPE_UNMD:
 		offset = 0;
 		/* Decode pairs: <Interface_ID (4 bytes), Channel_status (4 bytes)> */
-		while (offset < (lmp_obj_len-(int)sizeof(struct lmp_object_header)) ) {
+		while (offset+8 <= obj_tlen) {
 			printf("\n\t    Interface ID: %s (0x%08x)",
 			ipaddr_string(obj_tptr+offset),
 			EXTRACT_32BITS(obj_tptr+offset));
 			
-			printf("\n\t\t    Active: %s (%u)", 		(EXTRACT_32BITS(obj_tptr+offset+4)>>31) ? 
+			printf("\n\t\t    Active: %s (%u)",
+			       (EXTRACT_32BITS(obj_tptr+offset+4)>>31) ?
 						"Allocated" : "Non-allocated",
 				(EXTRACT_32BITS(obj_tptr+offset+4)>>31));
 			
-			printf("\n\t\t    Direction: %s (%u)", (EXTRACT_32BITS(obj_tptr+offset+4)>>30)&0x1 ? 
+			printf("\n\t\t    Direction: %s (%u)",
+			       (EXTRACT_32BITS(obj_tptr+offset+4)>>30)&0x1 ?
 						"Transmit" : "Receive",
 				(EXTRACT_32BITS(obj_tptr+offset+4)>>30)&0x1);	
 						
@@ -718,6 +885,60 @@ lmp_print(register const u_char *pptr, r
                 break;
 #ifdef INET6       
 	    case LMP_CTYPE_IPV6:
+		    offset = 0;
+		/* Decode pairs: <Interface_ID (16 bytes), Channel_status (4 bytes)> */
+		while (offset+20 <= obj_tlen) {
+			printf("\n\t    Interface ID: %s (0x%08x)",
+			ip6addr_string(obj_tptr+offset),
+			EXTRACT_32BITS(obj_tptr+offset));
+
+			printf("\n\t\t    Active: %s (%u)",
+			       (EXTRACT_32BITS(obj_tptr+offset+16)>>31) ?
+			       "Allocated" : "Non-allocated",
+			       (EXTRACT_32BITS(obj_tptr+offset+16)>>31));
+
+			printf("\n\t\t    Direction: %s (%u)",
+			       (EXTRACT_32BITS(obj_tptr+offset+16)>>30)&0x1 ?
+			       "Transmit" : "Receive",
+			       (EXTRACT_32BITS(obj_tptr+offset+16)>>30)&0x1);
+
+			printf("\n\t\t    Channel Status: %s (%u)",
+			       tok2str(lmp_obj_channel_status_values,
+				       "Unknown",
+				       EXTRACT_32BITS(obj_tptr+offset+16)&0x3FFFFFF),
+			       EXTRACT_32BITS(obj_tptr+offset+16)&0x3FFFFFF);
+			offset+=20;
+		}
+                break;
+
+			    case LMP_CTYPE_UNMD:
+		offset = 0;
+		/* Decode pairs: <Interface_ID (4 bytes), Channel_status (4 bytes)> */
+		while (offset+8 <= obj_tlen) {
+			printf("\n\t    Interface ID: %u (0x%08x)",
+			       EXTRACT_32BITS(obj_tptr+offset),
+			       EXTRACT_32BITS(obj_tptr+offset));
+
+			printf("\n\t\t    Active: %s (%u)",
+			       (EXTRACT_32BITS(obj_tptr+offset+4)>>31) ?
+			       "Allocated" : "Non-allocated",
+			       (EXTRACT_32BITS(obj_tptr+offset+4)>>31));
+
+			printf("\n\t\t    Direction: %s (%u)",
+			       (EXTRACT_32BITS(obj_tptr+offset+4)>>30)&0x1 ?
+			       "Transmit" : "Receive",
+			       (EXTRACT_32BITS(obj_tptr+offset+4)>>30)&0x1);
+
+			printf("\n\t\t    Channel Status: %s (%u)",
+			       tok2str(lmp_obj_channel_status_values,
+				       "Unknown",
+				       EXTRACT_32BITS(obj_tptr+offset+4)&0x3FFFFFF),
+			       EXTRACT_32BITS(obj_tptr+offset+4)&0x3FFFFFF);
+			offset+=8;
+		}
+                break;
+
+
 #endif
             default:
                 hexdump=TRUE;
@@ -727,9 +948,8 @@ lmp_print(register const u_char *pptr, r
 	case LMP_OBJ_CHANNEL_STATUS_REQ:
             switch(lmp_obj_ctype) {
 	    case LMP_CTYPE_IPV4:
-	    case LMP_CTYPE_UNMD:
 		offset = 0;
-		while (offset < (lmp_obj_len-(int)sizeof(struct lmp_object_header)) ) {
+		while (offset+4 <= obj_tlen) {
 			printf("\n\t    Interface ID: %s (0x%08x)",
 			ipaddr_string(obj_tptr+offset),
 			EXTRACT_32BITS(obj_tptr+offset));
@@ -738,6 +958,24 @@ lmp_print(register const u_char *pptr, r
                 break;
 #ifdef INET6       
 	    case LMP_CTYPE_IPV6:
+		offset = 0;
+		while (offset+16 <= obj_tlen) {
+			printf("\n\t    Interface ID: %s (0x%08x)",
+			       ip6addr_string(obj_tptr+offset),
+			       EXTRACT_32BITS(obj_tptr+offset));
+			offset+=16;
+		}
+                break;
+
+	    case LMP_CTYPE_UNMD:
+		offset = 0;
+		while (offset+4 <= obj_tlen) {
+			printf("\n\t    Interface ID: %u (0x%08x)",
+			       EXTRACT_32BITS(obj_tptr+offset),
+			       EXTRACT_32BITS(obj_tptr+offset));
+			offset+=4;
+		}
+                break;
 #endif
 	    default:
                 hexdump=TRUE;
@@ -747,6 +985,10 @@ lmp_print(register const u_char *pptr, r
         case LMP_OBJ_ERROR_CODE:
 	    switch(lmp_obj_ctype) {
             case LMP_CTYPE_BEGIN_VERIFY_ERROR:
+		if (obj_tlen != 4) {
+			printf(" (not correct for object)");
+			break;
+                }
 		printf("\n\t    Error Code: %s",
 		bittok2str(lmp_obj_begin_verify_error_values,
 			"none",
@@ -754,6 +996,10 @@ lmp_print(register const u_char *pptr, r
                 break;
 		
             case LMP_CTYPE_LINK_SUMMARY_ERROR:
+		if (obj_tlen != 4) {
+			printf(" (not correct for object)");
+			break;
+                }
 		printf("\n\t    Error Code: %s",
 		bittok2str(lmp_obj_link_summary_error_values,
 			"none",
@@ -767,51 +1013,59 @@ lmp_print(register const u_char *pptr, r
 	case LMP_OBJ_SERVICE_CONFIG:
 	    switch (lmp_obj_ctype) {
 	    case LMP_CTYPE_SERVICE_CONFIG_SP:
-		
+                if (obj_tlen != 4) {
+			printf(" (not correct for object)");
+			break;
+                }		
 		printf("\n\t Flags: %s",
 		       bittok2str(lmp_obj_service_config_sp_flag_values,
 				  "none", 
-				  EXTRACT_16BITS(obj_tptr)>>8));
+				  EXTRACT_8BITS(obj_tptr)));
 
 		printf("\n\t  UNI Version: %u",
-		       EXTRACT_16BITS(obj_tptr) & 0x00FF);
+		       EXTRACT_8BITS(obj_tptr+1));
 
 		break;
 		
             case LMP_CTYPE_SERVICE_CONFIG_CPSA:
+		if (obj_tlen != 16) {
+			printf(" (not correct for object)");
+			break;
+                }
 		
-		link_type = EXTRACT_16BITS(obj_tptr)>>8;
+		link_type = EXTRACT_8BITS(obj_tptr);
 		
 		printf("\n\t Link Type: %s (%u)",
 		       tok2str(lmp_sd_service_config_cpsa_link_type_values,
 			       "Unknown", link_type),
 		       link_type);
 		
-		if (link_type == LMP_SD_SERVICE_CONFIG_CPSA_LINK_TYPE_SDH) {
-		    printf("\n\t Signal Type: %s (%u)",
-			   tok2str(lmp_sd_service_config_cpsa_signal_type_sdh_values,
-				   "Unknown",
-				   EXTRACT_16BITS(obj_tptr) & 0x00FF),
-			   EXTRACT_16BITS(obj_tptr) & 0x00FF);
-		}
-		
-		if (link_type == LMP_SD_SERVICE_CONFIG_CPSA_LINK_TYPE_SONET) {
-		    printf("\n\t Signal Type: %s (%u)",
-			   tok2str(lmp_sd_service_config_cpsa_signal_type_sonet_values,
-				   "Unknown",
-				   EXTRACT_16BITS(obj_tptr) & 0x00FF),
-			   EXTRACT_16BITS(obj_tptr) & 0x00FF);
+		switch (link_type) {
+		    case LMP_SD_SERVICE_CONFIG_CPSA_LINK_TYPE_SDH:
+			    printf("\n\t Signal Type: %s (%u)",
+				   tok2str(lmp_sd_service_config_cpsa_signal_type_sdh_values,
+					   "Unknown",
+					   EXTRACT_8BITS(obj_tptr+1)),
+				   EXTRACT_8BITS(obj_tptr+1));
+			    break;
+		
+		    case LMP_SD_SERVICE_CONFIG_CPSA_LINK_TYPE_SONET:
+			    printf("\n\t Signal Type: %s (%u)",
+				   tok2str(lmp_sd_service_config_cpsa_signal_type_sonet_values,
+					   "Unknown",
+					   EXTRACT_8BITS(obj_tptr+1)),
+				   EXTRACT_8BITS(obj_tptr+1));
 		}
 		
 		printf("\n\t Transparency: %s",
 		       bittok2str(lmp_obj_service_config_cpsa_tp_flag_values,
 				  "none",
-				  EXTRACT_16BITS(obj_tptr+2)>>8));
+				  EXTRACT_8BITS(obj_tptr+2)));
 		
 		printf("\n\t Contiguous Concatenation Types: %s",
 		       bittok2str(lmp_obj_service_config_cpsa_cct_flag_values,
 				  "none",
-				  EXTRACT_16BITS(obj_tptr+2)>>8 & 0x00FF));
+				  EXTRACT_8BITS(obj_tptr+3)));
 		
 		printf("\n\t Minimum NCC: %u",
 		       EXTRACT_16BITS(obj_tptr+4));
@@ -832,6 +1086,10 @@ lmp_print(register const u_char *pptr, r
 		break;
 		
 	    case LMP_CTYPE_SERVICE_CONFIG_TRANSPARENCY_TCM:
+		if (obj_tlen != 8) {
+			printf(" (not correct for object)");
+			break;
+                }
 		
 		printf("\n\t Transparency Flags: %s",
 		       bittok2str(
@@ -848,12 +1106,16 @@ lmp_print(register const u_char *pptr, r
 		break;
 		
 	    case LMP_CTYPE_SERVICE_CONFIG_NETWORK_DIVERSITY:
+		if (obj_tlen != 4) {
+			printf(" (not correct for object)");
+			break;
+                }
 		
 		printf("\n\t Diversity: Flags: %s",
 		       bittok2str(
 			   lmp_obj_service_config_nsa_network_diversity_flag_values,
 			   "none",
-			   EXTRACT_16BITS(obj_tptr+2) & 0x00FF));
+			   EXTRACT_8BITS(obj_tptr+3)));
 		break;
 
 	    default:
