]> The Tcpdump Group git mirrors - tcpdump/commitdiff
LDP: Fix an undefined behavior at runtime
authorFrancois-Xavier Le Bail <[email protected]>
Sun, 18 Aug 2019 15:47:19 +0000 (17:47 +0200)
committerFrancois-Xavier Le Bail <[email protected]>
Sun, 18 Aug 2019 15:47:19 +0000 (17:47 +0200)
The error was:
print-ldp.c:557:13: runtime error: unsigned integer overflow: 32 - 34
cannot be represented in type 'unsigned int'

(backported from commit f50b5d79085dd3c5212b52a99697cb4ccd4dea6d)

print-ldp.c

index 2a3d1f97303ee4470f92d84f6a080188259710fb..1bb27fe4169535619ac2f0cf8ce048625de0f5f4 100644 (file)
@@ -210,7 +210,7 @@ static const struct tok ldp_fec_martini_ifparm_vccv_cv_values[] = {
     { 0, NULL}
 };
 
-static int ldp_pdu_print(netdissect_options *, register const u_char *);
+static u_int ldp_pdu_print(netdissect_options *, register const u_char *);
 
 /*
  * ldp tlv header
@@ -546,17 +546,23 @@ void
 ldp_print(netdissect_options *ndo,
           register const u_char *pptr, register u_int len)
 {
-    int processed;
+    u_int processed;
     while (len > (sizeof(struct ldp_common_header) + sizeof(struct ldp_msg_header))) {
         processed = ldp_pdu_print(ndo, pptr);
         if (processed == 0)
             return;
+        if (len < processed) {
+            ND_PRINT((ndo, " [remaining length %u < %u]", len, processed));
+            ND_PRINT((ndo, "%s", istr));
+            break;
+
+        }
         len -= processed;
         pptr += processed;
     }
 }
 
-static int
+static u_int
 ldp_pdu_print(netdissect_options *ndo,
               register const u_char *pptr)
 {