]> The Tcpdump Group git mirrors - tcpdump/commitdiff
Ethernet: Add a length check
authorFrancois-Xavier Le Bail <[email protected]>
Fri, 5 Nov 2021 20:48:31 +0000 (21:48 +0100)
committerFrancois-Xavier Le Bail <[email protected]>
Sun, 21 Nov 2021 15:26:08 +0000 (16:26 +0100)
This fix some undefined behaviors at runtime.

The errors were like:

print-ether.c:241:11: runtime error: unsigned integer overflow:
  1 - 2 cannot be represented in type 'unsigned int'
print-ether.c:242:11: runtime error: unsigned integer overflow:
  1 - 2 cannot be represented in type 'unsigned int'

Moreover:
Fix indentation.

print-ether.c

index 954668c4a2b5bf759a4ae478ada2a2f6c7912a03..c47749c309033373700dfffdc8adc58ea8d77910 100644 (file)
@@ -222,7 +222,7 @@ recurse:
                }
 
                int ret = macsec_print(ndo, &p, &length, &caplen, &hdrlen,
-                   &src, &dst);
+                                      &src, &dst);
 
                if (ret == 0) {
                        /* Payload is encrypted; print it as raw data. */
@@ -238,6 +238,7 @@ recurse:
                         */
                        length_type = GET_BE_U_2(p);
 
+                       ND_LCHECK_U(caplen, 2);
                        length -= 2;
                        caplen -= 2;
                        p += 2;
@@ -403,6 +404,7 @@ recurse:
                                ND_DEFAULTPRINT(p, caplen);
                }
        }
+invalid:
        return hdrlen;
 }