X-Git-Url: https://git.tcpdump.org/tcpdump/blobdiff_plain/64e8f9a9ed91a3cbfa8e66367f87ef50a1d62b99..refs/pull/926/head:/print-rpki-rtr.c diff --git a/print-rpki-rtr.c b/print-rpki-rtr.c index a51c4a1f..780845f2 100644 --- a/print-rpki-rtr.c +++ b/print-rpki-rtr.c @@ -25,8 +25,7 @@ #include "netdissect-stdinc.h" -#include - +#define ND_LONGJMP_FROM_TCHECK #include "netdissect.h" #include "extract.h" #include "addrtoname.h" @@ -125,7 +124,6 @@ static const struct tok rpki_rtr_error_codes[] = { /* * Build a indentation string for a given indentation level. - * XXX this should be really in util.c */ static char * indent_string (u_int indent) @@ -179,25 +177,24 @@ rpki_rtr_pdu_print(netdissect_options *ndo, const u_char *tptr, const u_int len, const rpki_rtr_pdu *pdu_header; u_int pdu_type, pdu_len, hexdump; const u_char *msg; + uint8_t pdu_ver; - /* Protocol Version */ - ND_TCHECK_1(tptr); - if (GET_U_1(tptr) != 0) { + if (len < sizeof(rpki_rtr_pdu)) { + ND_PRINT("(%u bytes is too few to decode)", len); + goto invalid; + } + pdu_header = (const rpki_rtr_pdu *)tptr; + pdu_ver = GET_U_1(pdu_header->version); + if (pdu_ver != 0) { /* Skip the rest of the input buffer because even if this is * a well-formed PDU of a future RPKI-Router protocol version * followed by a well-formed PDU of RPKI-Router protocol * version 0, there is no way to know exactly how to skip the * current PDU. */ - ND_PRINT("%sRPKI-RTRv%u (unknown)", indent_string(8), GET_U_1(tptr)); + ND_PRINT("%sRPKI-RTRv%u (unknown)", indent_string(8), pdu_ver); return len; } - if (len < sizeof(rpki_rtr_pdu)) { - ND_PRINT("(%u bytes is too few to decode)", len); - goto invalid; - } - ND_TCHECK_LEN(tptr, sizeof(rpki_rtr_pdu)); - pdu_header = (const rpki_rtr_pdu *)tptr; pdu_type = GET_U_1(pdu_header->pdu_type); pdu_len = GET_BE_U_4(pdu_header->length); /* Do not check bounds with pdu_len yet, do it in the case blocks @@ -208,7 +205,7 @@ rpki_rtr_pdu_print(netdissect_options *ndo, const u_char *tptr, const u_int len, ND_PRINT("%sRPKI-RTRv%u, %s PDU (%u), length: %u", indent_string(8), - GET_U_1(pdu_header->version), + pdu_ver, tok2str(rpki_rtr_pdu_values, "Unknown", pdu_type), pdu_type, pdu_len); if (pdu_len < sizeof(rpki_rtr_pdu) || pdu_len > len) @@ -224,7 +221,6 @@ rpki_rtr_pdu_print(netdissect_options *ndo, const u_char *tptr, const u_int len, case RPKI_RTR_END_OF_DATA_PDU: if (pdu_len != sizeof(rpki_rtr_pdu) + 4) goto invalid; - ND_TCHECK_LEN(tptr, pdu_len); msg = (const u_char *)(pdu_header + 1); ND_PRINT("%sSession ID: 0x%04x, Serial: %u", indent_string(indent+2), @@ -259,9 +255,8 @@ rpki_rtr_pdu_print(netdissect_options *ndo, const u_char *tptr, const u_int len, { const rpki_rtr_pdu_ipv4_prefix *pdu; - if (pdu_len != sizeof(rpki_rtr_pdu) + 12) + if (pdu_len != sizeof(rpki_rtr_pdu_ipv4_prefix)) goto invalid; - ND_TCHECK_LEN(tptr, pdu_len); pdu = (const rpki_rtr_pdu_ipv4_prefix *)tptr; ND_PRINT("%sIPv4 Prefix %s/%u-%u, origin-as %u, flags 0x%02x", indent_string(indent+2), @@ -275,9 +270,8 @@ rpki_rtr_pdu_print(netdissect_options *ndo, const u_char *tptr, const u_int len, { const rpki_rtr_pdu_ipv6_prefix *pdu; - if (pdu_len != sizeof(rpki_rtr_pdu) + 24) + if (pdu_len != sizeof(rpki_rtr_pdu_ipv6_prefix)) goto invalid; - ND_TCHECK_LEN(tptr, pdu_len); pdu = (const rpki_rtr_pdu_ipv6_prefix *)tptr; ND_PRINT("%sIPv6 Prefix %s/%u-%u, origin-as %u, flags 0x%02x", indent_string(indent+2), @@ -296,13 +290,12 @@ rpki_rtr_pdu_print(netdissect_options *ndo, const u_char *tptr, const u_int len, /* Do not test for the "Length of Error Text" data element yet. */ if (pdu_len < tlen + 4) goto invalid; - ND_TCHECK_LEN(tptr, tlen + 4); - /* Safe up to and including the "Length of Encapsulated PDU" - * data element, more data elements may be present. - */ pdu = (const rpki_rtr_pdu_error_report *)tptr; encapsulated_pdu_length = GET_BE_U_4(pdu->encapsulated_pdu_length); tlen += 4; + /* Safe up to and including the "Length of Encapsulated PDU" + * data element, more data elements may be present. + */ error_code = GET_BE_U_2(pdu->pdu_header.u.error_code); ND_PRINT("%sError code: %s (%u), Encapsulated PDU length: %u", @@ -338,24 +331,20 @@ rpki_rtr_pdu_print(netdissect_options *ndo, const u_char *tptr, const u_int len, if (pdu_len < tlen + 4) goto invalid; - ND_TCHECK_LEN(tptr, tlen + 4); - /* Safe up to and including the "Length of Error Text" data element, - * one more data element may be present. - */ - /* * Extract, trail-zero and print the Error message. */ text_length = GET_BE_U_4(tptr + tlen); tlen += 4; + /* Safe up to and including the "Length of Error Text" data element, + * one more data element may be present. + */ if (text_length) { if (pdu_len < tlen + text_length) goto invalid; - /* nd_printn() makes the bounds check */ ND_PRINT("%sError text: ", indent_string(indent+2)); - if (nd_printn(ndo, tptr + tlen, text_length, ndo->ndo_snapend)) - goto trunc; + nd_printjn(ndo, tptr + tlen, text_length); } } break; @@ -379,9 +368,6 @@ invalid: nd_print_invalid(ndo); ND_TCHECK_LEN(tptr, len); return len; -trunc: - nd_print_trunc(ndo); - return len; } void