X-Git-Url: https://git.tcpdump.org/tcpdump/blobdiff_plain/f4c23604a0f60fbc0cf1ed0ffacd77fb2f24bd16..47b02443f099fc93a7c69041d30bf6f6be552ece:/print-zeromq.c diff --git a/print-zeromq.c b/print-zeromq.c index e1410674..a23d98a1 100644 --- a/print-zeromq.c +++ b/print-zeromq.c @@ -1,7 +1,4 @@ /* - * This file implements decoding of ZeroMQ network protocol(s). - * - * * Copyright (c) 2013 The TCPDUMP project * All rights reserved. * @@ -28,6 +25,8 @@ * POSSIBILITY OF SUCH DAMAGE. */ +/* \summary: ZeroMQ Message Transport Protocol (ZMTP) printer */ + #ifdef HAVE_CONFIG_H #include "config.h" #endif @@ -86,7 +85,7 @@ zmtp1_print_frame(netdissect_options *ndo, const u_char *cp, const u_char *ep) if (cp[0] != 0xFF) { header_len = 1; /* length */ body_len_declared = cp[0]; - ND_PRINT((ndo, " frame flags+body (8-bit) length %u", body_len_declared)); + ND_PRINT((ndo, " frame flags+body (8-bit) length %" PRIu64, body_len_declared)); } else { header_len = 1 + 8; /* 0xFF, length */ ND_PRINT((ndo, " frame flags+body (64-bit) length")); @@ -126,8 +125,15 @@ zmtp1_print_frame(netdissect_options *ndo, const u_char *cp, const u_char *ep) } } - ND_TCHECK2(*cp, header_len + body_len_declared); /* Next frame within the buffer ? */ - return cp + header_len + body_len_declared; + /* + * Do not advance cp by the sum of header_len and body_len_declared + * before each offset has successfully passed ND_TCHECK2() as the + * sum can roll over (9 + 0xfffffffffffffff7 = 0) and cause an + * infinite loop. + */ + cp += header_len; + ND_TCHECK2(*cp, body_len_declared); /* Next frame within the buffer ? */ + return cp + body_len_declared; trunc: ND_PRINT((ndo, "%s", tstr));