X-Git-Url: https://git.tcpdump.org/tcpdump/blobdiff_plain/a7a448081310beb7ca63c52244a8348f4105606d..d6aacc676d8540f31d1df72b12b43fc9cde93df6:/print-isoclns.c diff --git a/print-isoclns.c b/print-isoclns.c index 229c3d7a..08be550d 100644 --- a/print-isoclns.c +++ b/print-isoclns.c @@ -562,7 +562,7 @@ struct isis_tlv_ptp_adj { uint8_t neighbor_extd_local_circuit_id[4]; }; -static void osi_print_cksum(netdissect_options *, const uint8_t *pptr, +static int osi_print_cksum(netdissect_options *, const uint8_t *pptr, uint16_t checksum, int checksum_offset, int length); static int clnp_print(netdissect_options *, const uint8_t *, u_int); static void esis_print(netdissect_options *, const uint8_t *, u_int); @@ -667,8 +667,9 @@ struct isis_tlv_lsp { #define ISIS_CSNP_HEADER_SIZE (sizeof(struct isis_csnp_header)) #define ISIS_PSNP_HEADER_SIZE (sizeof(struct isis_psnp_header)) -void isoclns_print(netdissect_options *ndo, - const uint8_t *p, u_int length, u_int caplen) +void +isoclns_print(netdissect_options *ndo, + const uint8_t *p, u_int length, u_int caplen) { if (caplen <= 1) { /* enough bytes on the wire ? */ ND_PRINT((ndo, "|OSI")); @@ -826,8 +827,9 @@ clnp_print(netdissect_options *ndo, EXTRACT_16BITS(clnp_header->segment_length), EXTRACT_16BITS(clnp_header->cksum))); - osi_print_cksum(ndo, optr, EXTRACT_16BITS(clnp_header->cksum), 7, - clnp_header->length_indicator); + if (osi_print_cksum(ndo, optr, EXTRACT_16BITS(clnp_header->cksum), 7, + clnp_header->length_indicator) == 0) + goto trunc; ND_PRINT((ndo, "\n\tFlags [%s]", bittok2str(clnp_flag_values, "none", clnp_flags))); @@ -1081,7 +1083,8 @@ esis_print(netdissect_options *ndo, ND_PRINT((ndo, ", v: %u%s", esis_header->version, esis_header->version == ESIS_VERSION ? "" : "unsupported" )); ND_PRINT((ndo, ", checksum: 0x%04x", EXTRACT_16BITS(esis_header->cksum))); - osi_print_cksum(ndo, pptr, EXTRACT_16BITS(esis_header->cksum), 7, li); + if (osi_print_cksum(ndo, pptr, EXTRACT_16BITS(esis_header->cksum), 7, li) == 0) + goto trunc; ND_PRINT((ndo, ", holding time: %us, length indicator: %u", EXTRACT_16BITS(esis_header->holdtime), li)); @@ -1301,12 +1304,8 @@ isis_print_mcid(netdissect_options *ndo, ND_TCHECK(*mcid); ND_PRINT((ndo, "ID: %d, Name: ", mcid->format_id)); - for(i=0; i<32; i++) - { - ND_PRINT((ndo, "%c", mcid->name[i])); - if(mcid->name[i] == '\0') - break; - } + if (fn_printzp(ndo, mcid->name, 32, ndo->ndo_snapend)) + goto trunc; ND_PRINT((ndo, "\n\t Lvl: %d", EXTRACT_16BITS(mcid->revision_lvl))); @@ -1865,12 +1864,9 @@ isis_print_is_reach_subtlv(netdissect_options *ndo, return(1); trunc: - ND_PRINT((ndo, "%s", ident)); - ND_PRINT((ndo, "%s", tstr)); return(0); } - /* * this is the common IS-REACH decoder it is called * from various EXTD-IS REACH style TLVs (22,24,222) @@ -2319,9 +2315,10 @@ isis_print(netdissect_options *ndo, EXTRACT_16BITS(header_lsp->remaining_lifetime), EXTRACT_16BITS(header_lsp->checksum))); - - osi_print_cksum(ndo, (uint8_t *)header_lsp->lsp_id, - EXTRACT_16BITS(header_lsp->checksum), 12, length-12); + if (osi_print_cksum(ndo, (uint8_t *)header_lsp->lsp_id, + EXTRACT_16BITS(header_lsp->checksum), + 12, length-12) == 0) + goto trunc; /* * Clear checksum and lifetime prior to signature verification. @@ -2331,7 +2328,6 @@ isis_print(netdissect_options *ndo, header_lsp->remaining_lifetime[0] = 0; header_lsp->remaining_lifetime[1] = 0; - ND_PRINT((ndo, ", PDU length: %u, Flags: [ %s", pdu_len, ISIS_MASK_LSP_OL_BIT(header_lsp->typeblock) ? "Overload bit set, " : "")); @@ -2653,11 +2649,8 @@ isis_print(netdissect_options *ndo, switch (*tptr) { case ISIS_SUBTLV_AUTH_SIMPLE: - for(i=1;indo_snapend)) + goto trunctlv; break; case ISIS_SUBTLV_AUTH_MD5: for(i=1;i0) { - if (!ND_TTEST2(*tptr, 1)) - goto trunctlv; - ND_PRINT((ndo, "%c", *tptr++)); - tmp--; - } + if (fn_printzp(ndo, tptr, tmp, ndo->ndo_snapend)) + goto trunctlv; break; case ISIS_TLV_SHARED_RISK_GROUP: @@ -2881,7 +2870,9 @@ isis_print(netdissect_options *ndo, * to avoid conflicts the checksum TLV is zeroed. * see rfc3358 for details */ - osi_print_cksum(ndo, optr, EXTRACT_16BITS(tptr), tptr-optr, length); + if (osi_print_cksum(ndo, optr, EXTRACT_16BITS(tptr), tptr-optr, + length) == 0) + goto trunc; break; case ISIS_TLV_POI: @@ -3089,7 +3080,7 @@ isis_print(netdissect_options *ndo, return(1); } -static void +static int osi_print_cksum(netdissect_options *ndo, const uint8_t *pptr, uint16_t checksum, int checksum_offset, int length) { @@ -3107,23 +3098,22 @@ osi_print_cksum(netdissect_options *ndo, const uint8_t *pptr, || checksum_offset > ndo->ndo_snaplen || checksum_offset > length) { ND_PRINT((ndo, " (unverified)")); + return 1; } else { - const char *truncated = "trunc"; #if 0 printf("\nosi_print_cksum: %p %u %u %u\n", pptr, checksum_offset, length, ndo->ndo_snaplen); - ND_TCHECK2(pptr, checksum_offset+length); #endif + ND_TCHECK2(*pptr, length); calculated_checksum = create_osi_cksum(pptr, checksum_offset, length); if (checksum == calculated_checksum) { ND_PRINT((ndo, " (correct)")); } else { - truncated = "incorrect"; -#if 0 - trunc: -#endif - ND_PRINT((ndo, " (%s should be 0x%04x)", truncated, calculated_checksum)); + ND_PRINT((ndo, " (incorrect should be 0x%04x)", calculated_checksum)); } + return 1; } +trunc: + return 0; } /*