From: Denis Ovsienko Date: Mon, 12 Oct 2020 21:11:37 +0000 (+0100) Subject: PPPoE: Modernize packet parsing style. X-Git-Tag: tcpdump-4.99-bp~109 X-Git-Url: https://git.tcpdump.org/tcpdump/commitdiff_plain/05a996fc3f4f85f34e6ff151adcb70538863a861 PPPoE: Modernize packet parsing style. Enable ND_LONGJMP_FROM_TCHECK, remove a redundant custom bounds check and a variable, report an undersized header as an invalid packet with the reason. --- diff --git a/print-pppoe.c b/print-pppoe.c index 50ae0996..65518dff 100644 --- a/print-pppoe.c +++ b/print-pppoe.c @@ -31,6 +31,7 @@ #include "netdissect-ctype.h" +#define ND_LONGJMP_FROM_TCHECK #include "netdissect.h" #include "extract.h" @@ -97,18 +98,13 @@ u_int pppoe_print(netdissect_options *ndo, const u_char *bp, u_int length) { uint16_t pppoe_ver, pppoe_type, pppoe_code, pppoe_sessionid; - u_int pppoe_length, caplen; + u_int pppoe_length; const u_char *pppoe_packet, *pppoe_payload; ndo->ndo_protocol = "pppoe"; - caplen = ndo->ndo_snapend - bp; - if (caplen < PPPOE_HDRLEN) { - nd_print_trunc(ndo); - return caplen; - } if (length < PPPOE_HDRLEN) { - nd_print_trunc(ndo); - return length; + ND_PRINT(" (length %u < %u)", length, PPPOE_HDRLEN); + goto invalid; } length -= PPPOE_HDRLEN; pppoe_packet = bp; @@ -202,8 +198,9 @@ pppoe_print(netdissect_options *ndo, const u_char *bp, u_int length) ND_PRINT(" "); return (PPPOE_HDRLEN + ppp_print(ndo, pppoe_payload, pppoe_length)); } + /* NOTREACHED */ -trunc: - nd_print_trunc(ndo); - return PPPOE_HDRLEN; +invalid: + nd_print_invalid(ndo); + return 0; }