mirror of
https://github.com/the-tcpdump-group/tcpdump.git
synced 2024-12-14 12:24:25 +08:00
EGP: Modernize packet parsing style.
Enable ND_LONGJMP_FROM_TCHECK. Report invalid packets as invalid.
This commit is contained in:
parent
b05797e0df
commit
e6cf3b7fdb
2
CHANGES
2
CHANGES
@ -2,7 +2,7 @@ Monthday, Month DD, YYYY by gharris and denis
|
|||||||
Summary for 5.0.0 tcpdump release (so far!)
|
Summary for 5.0.0 tcpdump release (so far!)
|
||||||
Source code:
|
Source code:
|
||||||
Use %zu when printing a sizeof to squelch compiler warnings
|
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()
|
EGP: Replace custom code with tok2str()
|
||||||
EIGRP: Get the packet header fields right.
|
EIGRP: Get the packet header fields right.
|
||||||
|
|
||||||
|
27
print-egp.c
27
print-egp.c
@ -28,6 +28,7 @@
|
|||||||
|
|
||||||
#include "netdissect-stdinc.h"
|
#include "netdissect-stdinc.h"
|
||||||
|
|
||||||
|
#define ND_LONGJMP_FROM_TCHECK
|
||||||
#include "netdissect.h"
|
#include "netdissect.h"
|
||||||
#include "addrtoname.h"
|
#include "addrtoname.h"
|
||||||
#include "extract.h"
|
#include "extract.h"
|
||||||
@ -179,7 +180,7 @@ egpnr_print(netdissect_options *ndo,
|
|||||||
/* Pickup host part of gateway address */
|
/* Pickup host part of gateway address */
|
||||||
addr = 0;
|
addr = 0;
|
||||||
if (length < 4 - netlen)
|
if (length < 4 - netlen)
|
||||||
goto trunc;
|
goto invalid;
|
||||||
ND_TCHECK_LEN(cp, 4 - netlen);
|
ND_TCHECK_LEN(cp, 4 - netlen);
|
||||||
switch (netlen) {
|
switch (netlen) {
|
||||||
|
|
||||||
@ -199,7 +200,7 @@ egpnr_print(netdissect_options *ndo,
|
|||||||
addr |= net;
|
addr |= net;
|
||||||
length -= 4 - netlen;
|
length -= 4 - netlen;
|
||||||
if (length < 1)
|
if (length < 1)
|
||||||
goto trunc;
|
goto invalid;
|
||||||
distances = GET_U_1(cp);
|
distances = GET_U_1(cp);
|
||||||
cp++;
|
cp++;
|
||||||
length--;
|
length--;
|
||||||
@ -211,7 +212,7 @@ egpnr_print(netdissect_options *ndo,
|
|||||||
ND_PRINT("(");
|
ND_PRINT("(");
|
||||||
while (distances != 0) {
|
while (distances != 0) {
|
||||||
if (length < 2)
|
if (length < 2)
|
||||||
goto trunc;
|
goto invalid;
|
||||||
ND_PRINT("%sd%u:", comma, GET_U_1(cp));
|
ND_PRINT("%sd%u:", comma, GET_U_1(cp));
|
||||||
cp++;
|
cp++;
|
||||||
comma = ", ";
|
comma = ", ";
|
||||||
@ -221,19 +222,19 @@ egpnr_print(netdissect_options *ndo,
|
|||||||
while (networks != 0) {
|
while (networks != 0) {
|
||||||
/* Pickup network number */
|
/* Pickup network number */
|
||||||
if (length < 1)
|
if (length < 1)
|
||||||
goto trunc;
|
goto invalid;
|
||||||
addr = ((uint32_t) GET_U_1(cp)) << 24;
|
addr = ((uint32_t) GET_U_1(cp)) << 24;
|
||||||
cp++;
|
cp++;
|
||||||
length--;
|
length--;
|
||||||
if (IN_CLASSB(addr)) {
|
if (IN_CLASSB(addr)) {
|
||||||
if (length < 1)
|
if (length < 1)
|
||||||
goto trunc;
|
goto invalid;
|
||||||
addr |= ((uint32_t) GET_U_1(cp)) << 16;
|
addr |= ((uint32_t) GET_U_1(cp)) << 16;
|
||||||
cp++;
|
cp++;
|
||||||
length--;
|
length--;
|
||||||
} else if (!IN_CLASSA(addr)) {
|
} else if (!IN_CLASSA(addr)) {
|
||||||
if (length < 2)
|
if (length < 2)
|
||||||
goto trunc;
|
goto invalid;
|
||||||
addr |= ((uint32_t) GET_U_1(cp)) << 16;
|
addr |= ((uint32_t) GET_U_1(cp)) << 16;
|
||||||
cp++;
|
cp++;
|
||||||
addr |= ((uint32_t) GET_U_1(cp)) << 8;
|
addr |= ((uint32_t) GET_U_1(cp)) << 8;
|
||||||
@ -248,8 +249,8 @@ egpnr_print(netdissect_options *ndo,
|
|||||||
ND_PRINT(")");
|
ND_PRINT(")");
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
trunc:
|
invalid:
|
||||||
nd_print_trunc(ndo);
|
nd_print_invalid(ndo);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@ -264,10 +265,11 @@ egp_print(netdissect_options *ndo,
|
|||||||
|
|
||||||
ndo->ndo_protocol = "egp";
|
ndo->ndo_protocol = "egp";
|
||||||
egp = (const struct egp_packet *)bp;
|
egp = (const struct egp_packet *)bp;
|
||||||
if (length < sizeof(*egp) || !ND_TTEST_SIZE(egp)) {
|
if (length < sizeof(*egp)) {
|
||||||
nd_print_trunc(ndo);
|
ND_PRINT(" packet length %u < %zu", length, sizeof(*egp));
|
||||||
return;
|
goto invalid;
|
||||||
}
|
}
|
||||||
|
ND_TCHECK_SIZE(egp);
|
||||||
|
|
||||||
version = GET_U_1(egp->egp_version);
|
version = GET_U_1(egp->egp_version);
|
||||||
if (!ndo->ndo_vflag) {
|
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)));
|
ND_PRINT(" %s", tok2str(egp_reasons_str, "[reason %u]", GET_BE_U_2(egp->egp_reason)));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
return;
|
||||||
|
invalid:
|
||||||
|
nd_print_invalid(ndo);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user