summaryrefslogtreecommitdiff
path: root/print-ether.c
diff options
context:
space:
mode:
authorFrancois-Xavier Le Bail <devel.fx.lebail@orange.fr>2021-11-21 15:33:24 +0100
committerFrancois-Xavier Le Bail <devel.fx.lebail@orange.fr>2021-11-21 15:49:13 +0100
commitd52b757efa7b0678e34c0ffe32d1c0da29bbb604 (patch)
tree5992a60baa0cbed3999f3ab2214e471adcb154db /print-ether.c
parent84b51cad218840ece9115c72705f846060005c6f (diff)
downloadtcpdump-d52b757efa7b0678e34c0ffe32d1c0da29bbb604.tar.gz
Ethernet: Rework the length checks
Add a sanity check: packet length need to be >= capture length (Like a sanity check in print.c, pretty_print_packet() function) Remove a now useless test: Because packet length (length) >= capture length (caplen), when caplen >= ETHER_HDRLEN + switch_tag_len, length cannot be < ETHER_HDRLEN + switch_tag_len.
Diffstat (limited to 'print-ether.c')
-rw-r--r--print-ether.c9
1 files changed, 5 insertions, 4 deletions
diff --git a/print-ether.c b/print-ether.c
index 3aeda8f7..954668c4 100644
--- a/print-ether.c
+++ b/print-ether.c
@@ -150,14 +150,15 @@ ether_common_print(netdissect_options *ndo, const u_char *p, u_int length,
int llc_hdrlen;
struct lladdr_info src, dst;
+ if (length < caplen) {
+ ND_PRINT("[length %u < caplen %u]", length, caplen);
+ nd_print_invalid(ndo);
+ return length;
+ }
if (caplen < ETHER_HDRLEN + switch_tag_len) {
nd_print_trunc(ndo);
return caplen;
}
- if (length < ETHER_HDRLEN + switch_tag_len) {
- nd_print_trunc(ndo);
- return length;
- }
if (print_encap_header != NULL)
(*print_encap_header)(ndo, encap_header_arg);