Skip to content

Commit

Permalink
Use ND_TCHECK() to do bounds checking.
Browse files Browse the repository at this point in the history
While we're at it, just use the record count to when iterating over
records; the ND_TCHECK()s will make sure we don't run past the end of
the captured data.

Also get rid of an unused argument to cnfp_print().
  • Loading branch information
guyharris committed Nov 10, 2014
1 parent fa01fcd commit 9ed7ddb
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 12 deletions.
2 changes: 1 addition & 1 deletion netdissect.h
Original file line number Diff line number Diff line change
Expand Up @@ -478,7 +478,7 @@ extern u_int atm_if_print(netdissect_options *, const struct pcap_pkthdr *, cons
extern void vtp_print(netdissect_options *, const u_char *, u_int);
extern int mptcp_print(netdissect_options *, const u_char *, u_int, u_char);
extern void ntp_print(netdissect_options *, const u_char *, u_int);
extern void cnfp_print(netdissect_options *, const u_char *, const u_char *);
extern void cnfp_print(netdissect_options *, const u_char *);
extern void dvmrp_print(netdissect_options *, const u_char *, u_int);
extern void egp_print(netdissect_options *, const u_char *, u_int);
extern u_int enc_if_print(netdissect_options *, const struct pcap_pkthdr *, const u_char *);
Expand Down
27 changes: 17 additions & 10 deletions print-cnfp.c
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,7 @@ struct nfrec {
};

void
cnfp_print(netdissect_options *ndo,
const u_char *cp, const u_char *bp _U_)
cnfp_print(netdissect_options *ndo, const u_char *cp)
{
register const struct nfhdr *nh;
register const struct nfrec *nr;
Expand All @@ -87,9 +86,7 @@ cnfp_print(netdissect_options *ndo,
#endif

nh = (const struct nfhdr *)cp;

if ((const u_char *)(nh + 1) > ndo->ndo_snapend)
return;
ND_TCHECK(*nh);

nrecs = EXTRACT_32BITS(&nh->ver_cnt) & 0xffff;
ver = (EXTRACT_32BITS(&nh->ver_cnt) & 0xffff0000) >> 16;
Expand All @@ -110,18 +107,23 @@ cnfp_print(netdissect_options *ndo,
if (ver == 5 || ver == 6) {
ND_PRINT((ndo, "#%u, ", EXTRACT_32BITS(&nh->sequence)));
nr = (const struct nfrec *)&nh[1];
ndo->ndo_snaplen -= 24;
} else {
} else
nr = (const struct nfrec *)&nh->sequence;
ndo->ndo_snaplen -= 16;
}

ND_PRINT((ndo, "%2u recs", nrecs));

for (; nrecs-- && (const u_char *)(nr + 1) <= ndo->ndo_snapend; nr++) {
for (; nrecs != 0; nr++, nrecs--) {
char buf[20];
char asbuf[20];

/*
* Make sure we have the entire record.
*/
if (ver == 5 || ver == 6) {
ND_TCHECK(nr->masks);
} else {
ND_TCHECK(nr->proto_tos);
}
ND_PRINT((ndo, "\n started %u.%03u, last %u.%03u",
EXTRACT_32BITS(&nr->start_time)/1000,
EXTRACT_32BITS(&nr->start_time)%1000,
Expand Down Expand Up @@ -184,4 +186,9 @@ cnfp_print(netdissect_options *ndo,
EXTRACT_32BITS(&nr->packets),
EXTRACT_32BITS(&nr->octets), buf));
}
return;

trunc:
ND_PRINT((ndo, "[|cnfp]"));
return;
}
2 changes: 1 addition & 1 deletion print-udp.c
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,7 @@ udp_print(netdissect_options *ndo, register const u_char *bp, u_int length,

case PT_CNFP:
udpipaddr_print(ndo, ip, sport, dport);
cnfp_print(ndo, cp, (const u_char *)ip);
cnfp_print(ndo, cp);
break;

case PT_TFTP:
Expand Down

0 comments on commit 9ed7ddb

Please sign in to comment.