Skip to content

Commit 02bdfdc

Browse files
committed
MSDP: Modernize packet parsing
Use ND_ICHECK_U() in length/type tests and add an 'invalid' label. Remove the 'trunc' label. Move '#define ND_LONGJMP_FROM_TCHECK' just before '#include "netdissect.h"' as for all other uses.
1 parent 18ea57e commit 02bdfdc

File tree

2 files changed

+17
-20
lines changed

2 files changed

+17
-20
lines changed

CHANGES

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ DayOfTheWeek, Month DD, YYYY / The Tcpdump Group
4242
Remove unused missing/snprintf.c.
4343
Remove unused missing/strdup.c.
4444
(FIXME: somebody please wrap the line below just before the release)
45-
AODV, AppleTalk, BOOTP, CHDLC, DCCP, EAP, EGP, EIGRP, ForCES, Geneve, GRE, ICMP, Juniper, L2TP, mobile, NetFlow, NFLOG, NTP, OLSR, pflog, PGM, RADIUS, RIP, RSVP, SCTP, SNMP, TCP, UDP, vsock: Modernize packet parsing style
45+
AODV, AppleTalk, BOOTP, CHDLC, DCCP, EAP, EGP, EIGRP, ForCES, Geneve, GRE, ICMP, Juniper, L2TP, mobile, MSDP, NetFlow, NFLOG, NTP, OLSR, pflog, PGM, RADIUS, RIP, RSVP, SCTP, SNMP, TCP, UDP, vsock: Modernize packet parsing style
4646
DCCP, EGP: Replace custom code with tok2str()
4747
UDP: Clean up address and port printing.
4848
AppleTalk: Declutter appletalk.h.

print-msdp.c

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@
2020

2121
#include <config.h>
2222

23-
#define ND_LONGJMP_FROM_TCHECK
2423
#include "netdissect-stdinc.h"
2524

25+
#define ND_LONGJMP_FROM_TCHECK
2626
#include "netdissect.h"
2727
#include "addrtoname.h"
2828
#include "extract.h"
@@ -40,21 +40,20 @@ msdp_print(netdissect_options *ndo, const u_char *sp, u_int length)
4040
/* See if we think we're at the beginning of a compound packet */
4141
type = GET_U_1(sp);
4242
len = GET_BE_U_2(sp + 1);
43-
if (len > 1500 || len < 3 || type == 0 || type > MSDP_TYPE_MAX)
44-
goto trunc; /* not really truncated, but still not decodable */
43+
ND_ICHECK_U(len, >, 1500);
44+
ND_ICHECK_U(len, <, 3);
45+
ND_ICHECK_U(type, ==, 0);
46+
ND_ICHECK_U(type, >, MSDP_TYPE_MAX);
4547
while (length != 0) {
4648
unsigned int entry_count;
4749

48-
if (length < 3)
49-
goto trunc;
50+
ND_ICHECK_U(length, <, 3);
5051
type = GET_U_1(sp);
5152
len = GET_BE_U_2(sp + 1);
5253
if (len > 1400 || ndo->ndo_vflag)
5354
ND_PRINT(" [len %u]", len);
54-
if (len < 3)
55-
goto trunc;
56-
if (length < len)
57-
goto trunc;
55+
ND_ICHECK_U(len, <, 3);
56+
ND_ICHECK_U(length, <, len);
5857
switch (type) {
5958
case 1: /* IPv4 Source-Active */
6059
case 3: /* IPv4 Source-Active Response */
@@ -64,14 +63,12 @@ msdp_print(netdissect_options *ndo, const u_char *sp, u_int length)
6463
ND_PRINT(" SA-Response");
6564

6665
/* Entry Count */
67-
if (len < 4)
68-
goto trunc;
66+
ND_ICHECK_U(len, <, 4);
6967
entry_count = GET_U_1(sp + 3);
7068
ND_PRINT(" %u entries", entry_count);
7169

7270
/* RP Address */
73-
if (len < 8)
74-
goto trunc;
71+
ND_ICHECK_U(len, <, 8);
7572
/* XXX -print this based on ndo_vflag? */
7673
ND_TCHECK_LEN(sp + 4, 4);
7774

@@ -93,13 +90,11 @@ msdp_print(netdissect_options *ndo, const u_char *sp, u_int length)
9390
ND_PRINT(" SA-Request");
9491

9592
/* Reserved */
96-
if (len < 4)
97-
goto trunc;
93+
ND_ICHECK_U(len, <, 4);
9894
ND_TCHECK_1(sp + 3);
9995

10096
/* Group Address */
101-
if (len < 8)
102-
goto trunc;
97+
ND_ICHECK_U(len, <, 8);
10398
if (len != 8)
10499
ND_PRINT("[len=%u] ", len);
105100
ND_PRINT(" for %s", GET_IPADDR_STRING(sp + 4));
@@ -121,6 +116,8 @@ msdp_print(netdissect_options *ndo, const u_char *sp, u_int length)
121116
length -= len;
122117
}
123118
return;
124-
trunc:
125-
nd_print_trunc(ndo);
119+
120+
invalid:
121+
nd_print_invalid(ndo);
122+
126123
}

0 commit comments

Comments
 (0)