X-Git-Url: https://git.tcpdump.org/tcpdump/blobdiff_plain/db3c742cd74bddea8d135fbabb0c9f7065a1d779..refs/heads/master:/print-rip.c diff --git a/print-rip.c b/print-rip.c index e9262e10..a399c610 100644 --- a/print-rip.c +++ b/print-rip.c @@ -23,9 +23,7 @@ /* specification: RFC 1058, RFC 2453, RFC 4822 */ -#ifdef HAVE_CONFIG_H #include -#endif #include "netdissect-stdinc.h" @@ -195,11 +193,10 @@ rip_entry_print_v1(netdissect_options *ndo, const u_char *p, const struct rip_netinfo_v1 *ni = (const struct rip_netinfo_v1 *)p; /* RFC 1058 */ - if (remaining < RIP_ROUTELEN) - goto invalid; + ND_ICHECKMSG_U("remaining data length", remaining, <, RIP_ROUTELEN); ND_TCHECK_SIZE(ni); family = GET_BE_U_2(ni->rip_family); - if (family != BSD_AFNUM_INET && family != 0) { + if (family != BSD_AF_INET && family != 0) { ND_PRINT("\n\t AFI %s, ", tok2str(bsd_af_values, "Unknown (%u)", family)); print_unknown_data(ndo, p + sizeof(*eh), "\n\t ", RIP_ROUTELEN - sizeof(*eh)); return (RIP_ROUTELEN); @@ -216,7 +213,7 @@ rip_entry_print_v1(netdissect_options *ndo, const u_char *p, GET_IPADDR_STRING(ni->rip_dest), GET_BE_U_4(ni->rip_metric)); return (RIP_ROUTELEN); - } /* BSD_AFNUM_INET */ + } /* BSD_AF_INET */ ND_PRINT("\n\t %s, metric: %u", GET_IPADDR_STRING(ni->rip_dest), GET_BE_U_4(ni->rip_metric)); @@ -233,8 +230,7 @@ rip_entry_print_v2(netdissect_options *ndo, const u_char *p, u_short family; const struct rip_netinfo_v2 *ni; - if (remaining < sizeof(*eh)) - goto invalid; + ND_ICHECKMSG_ZU("remaining data length", remaining, <, sizeof(*eh)); ND_TCHECK_SIZE(eh); family = GET_BE_U_2(eh->rip_family); if (family == 0xFFFF) { /* variable-sized authentication structures */ @@ -249,8 +245,8 @@ rip_entry_print_v2(netdissect_options *ndo, const u_char *p, const struct rip_auth_crypto_v2 *ch; ch = (const struct rip_auth_crypto_v2 *)p; - if (remaining < sizeof(*ch)) - goto invalid; + ND_ICHECKMSG_ZU("remaining data length", remaining, + <, sizeof(*ch)); ND_PRINT("\n\t Auth header:"); ND_PRINT(" Packet Len %u,", GET_BE_U_2(ch->rip_packet_len)); @@ -270,13 +266,13 @@ rip_entry_print_v2(netdissect_options *ndo, const u_char *p, print_unknown_data(ndo, p, "\n\t ", remaining); return (sizeof(*eh) + remaining); /* we don't know how long this is, so we go to the packet end */ } - } else if (family != BSD_AFNUM_INET && family != 0) { + } else if (family != BSD_AF_INET && family != 0) { ND_PRINT("\n\t AFI %s", tok2str(bsd_af_values, "Unknown (%u)", family)); print_unknown_data(ndo, p + sizeof(*eh), "\n\t ", RIP_ROUTELEN - sizeof(*eh)); - } else { /* BSD_AFNUM_INET or AFI 0 */ + } else { /* BSD_AF_INET or AFI 0 */ ni = (const struct rip_netinfo_v2 *)p; - if (remaining < sizeof(*ni)) - goto invalid; + ND_ICHECKMSG_ZU("remaining data length", remaining, <, + sizeof(*ni)); ND_PRINT("\n\t AFI %s, %15s/%-2d, tag 0x%04x, metric: %u, next-hop: ", tok2str(bsd_af_values, "%u", family), GET_IPADDR_STRING(ni->rip_dest), @@ -302,17 +298,18 @@ rip_print(netdissect_options *ndo, unsigned entry_size; ndo->ndo_protocol = "rip"; - if (len < sizeof(*rp)) { - ND_PRINT(" (packet length %u)", len); - goto invalid; - } + ND_PRINT("%s", (ndo->ndo_vflag >= 1) ? "\n\t" : ""); + nd_print_protocol_caps(ndo); + ND_ICHECKMSG_ZU("packet length", len, <, sizeof(*rp)); rp = (const struct rip *)p; vers = GET_U_1(rp->rip_vers); - ND_PRINT("%sRIPv%u", - (ndo->ndo_vflag >= 1) ? "\n\t" : "", - vers); + ND_PRINT("v%u", vers); + if (vers != 1 && vers != 2) { + ND_PRINT(" [version != 1 && version != 2]"); + goto invalid; + } /* dump version and lets see if we know the commands name*/ cmd = GET_U_1(rp->rip_cmd); @@ -340,11 +337,8 @@ rip_print(netdissect_options *ndo, /* Error */ goto invalid; } - if (len < entry_size) { - ND_PRINT(" [remaining entries length %u < %u]", - len, entry_size); - goto invalid; - } + ND_ICHECKMSG_U("remaining entries length", + len, <, entry_size); p += entry_size; len -= entry_size; } @@ -358,11 +352,8 @@ rip_print(netdissect_options *ndo, /* Error */ goto invalid; } - if (len < entry_size) { - ND_PRINT(" [remaining entries length %u < %u]", - len, entry_size); - goto invalid; - } + ND_ICHECKMSG_U("remaining entries length", + len, <, entry_size); p += entry_size; len -= entry_size; } @@ -392,7 +383,7 @@ rip_print(netdissect_options *ndo, break; } /* do we want to see an additionally hexdump ? */ - if (ndo->ndo_vflag> 1) { + if (ndo->ndo_vflag > 1 && ND_TTEST_LEN(p, len)) { if (!print_unknown_data(ndo, p, "\n\t", len)) return; }