summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenis Ovsienko <denis@ovsienko.info>2021-01-11 14:47:59 +0000
committerDenis Ovsienko <denis@ovsienko.info>2021-01-11 15:14:04 +0000
commite6cf3b7fdbac28fde2b588692866cfdfb9a21818 (patch)
treeca8a00667b4285f28e700ce5479d126125cf7713
parentb05797e0dfa2a8369432b15a5ac4f8cc89c5fdb9 (diff)
downloadtcpdump-e6cf3b7fdbac28fde2b588692866cfdfb9a21818.tar.gz
EGP: Modernize packet parsing style.
Enable ND_LONGJMP_FROM_TCHECK. Report invalid packets as invalid.
-rw-r--r--CHANGES2
-rw-r--r--print-egp.c27
2 files changed, 17 insertions, 12 deletions
diff --git a/CHANGES b/CHANGES
index 899410a9..f2a7e9bf 100644
--- a/CHANGES
+++ b/CHANGES
@@ -2,7 +2,7 @@ Monthday, Month DD, YYYY by gharris and denis
Summary for 5.0.0 tcpdump release (so far!)
Source code:
Use %zu when printing a sizeof to squelch compiler warnings
- BOOTP, EIGRP, Geneve, L2TP, OLSR, PGM, RSVP: Modernize packet parsing style
+ BOOTP, EGP, EIGRP, Geneve, L2TP, OLSR, PGM, RSVP: Modernize packet parsing style
EGP: Replace custom code with tok2str()
EIGRP: Get the packet header fields right.
diff --git a/print-egp.c b/print-egp.c
index 28adf7de..bb93b025 100644
--- a/print-egp.c
+++ b/print-egp.c
@@ -28,6 +28,7 @@
#include "netdissect-stdinc.h"
+#define ND_LONGJMP_FROM_TCHECK
#include "netdissect.h"
#include "addrtoname.h"
#include "extract.h"
@@ -179,7 +180,7 @@ egpnr_print(netdissect_options *ndo,
/* Pickup host part of gateway address */
addr = 0;
if (length < 4 - netlen)
- goto trunc;
+ goto invalid;
ND_TCHECK_LEN(cp, 4 - netlen);
switch (netlen) {
@@ -199,7 +200,7 @@ egpnr_print(netdissect_options *ndo,
addr |= net;
length -= 4 - netlen;
if (length < 1)
- goto trunc;
+ goto invalid;
distances = GET_U_1(cp);
cp++;
length--;
@@ -211,7 +212,7 @@ egpnr_print(netdissect_options *ndo,
ND_PRINT("(");
while (distances != 0) {
if (length < 2)
- goto trunc;
+ goto invalid;
ND_PRINT("%sd%u:", comma, GET_U_1(cp));
cp++;
comma = ", ";
@@ -221,19 +222,19 @@ egpnr_print(netdissect_options *ndo,
while (networks != 0) {
/* Pickup network number */
if (length < 1)
- goto trunc;
+ goto invalid;
addr = ((uint32_t) GET_U_1(cp)) << 24;
cp++;
length--;
if (IN_CLASSB(addr)) {
if (length < 1)
- goto trunc;
+ goto invalid;
addr |= ((uint32_t) GET_U_1(cp)) << 16;
cp++;
length--;
} else if (!IN_CLASSA(addr)) {
if (length < 2)
- goto trunc;
+ goto invalid;
addr |= ((uint32_t) GET_U_1(cp)) << 16;
cp++;
addr |= ((uint32_t) GET_U_1(cp)) << 8;
@@ -248,8 +249,8 @@ egpnr_print(netdissect_options *ndo,
ND_PRINT(")");
}
return;
-trunc:
- nd_print_trunc(ndo);
+invalid:
+ nd_print_invalid(ndo);
}
void
@@ -264,10 +265,11 @@ egp_print(netdissect_options *ndo,
ndo->ndo_protocol = "egp";
egp = (const struct egp_packet *)bp;
- if (length < sizeof(*egp) || !ND_TTEST_SIZE(egp)) {
- nd_print_trunc(ndo);
- return;
+ if (length < sizeof(*egp)) {
+ ND_PRINT(" packet length %u < %zu", length, sizeof(*egp));
+ goto invalid;
}
+ ND_TCHECK_SIZE(egp);
version = GET_U_1(egp->egp_version);
if (!ndo->ndo_vflag) {
@@ -369,4 +371,7 @@ egp_print(netdissect_options *ndo,
ND_PRINT(" %s", tok2str(egp_reasons_str, "[reason %u]", GET_BE_U_2(egp->egp_reason)));
break;
}
+ return;
+invalid:
+ nd_print_invalid(ndo);
}