From: Guy Harris Date: Tue, 16 Nov 2021 00:44:46 +0000 (-0800) Subject: LISP: don't decrement count variables unless we know they're not zero. X-Git-Tag: tcpdump-4.99.2~164 X-Git-Url: https://git.tcpdump.org/tcpdump/commitdiff_plain/8ff80fe575c15a4c65dae0554690f5afae1d5c81?ds=inline LISP: don't decrement count variables unless we know they're not zero. This fixes some undefined behavior warnings. (cherry picked from commit 913a9fa71293ce12b3c1dea3d93d3a97cf685625) --- diff --git a/print-lisp.c b/print-lisp.c index 0012e06e..756fff0f 100644 --- a/print-lisp.c +++ b/print-lisp.c @@ -283,8 +283,8 @@ lisp_print(netdissect_options *ndo, const u_char *bp, u_int length) goto invalid; /* Print all the EID records */ - while ((length > packet_offset) && (record_count--)) { - + while ((length > packet_offset) && (record_count != 0)) { + record_count--; ND_TCHECK_LEN(packet_iterator + packet_offset, MAP_REGISTER_EID_LEN); ND_PRINT("\n"); @@ -326,7 +326,8 @@ lisp_print(netdissect_options *ndo, const u_char *bp, u_int length) ND_PRINT(" %u locator(s)", loc_count); - while (loc_count--) { + while (loc_count != 0) { + loc_count--; ND_TCHECK_LEN(packet_iterator + packet_offset, MAP_REGISTER_LOC_LEN); lisp_loc = (const lisp_map_register_loc *) (packet_iterator + packet_offset);