]> The Tcpdump Group git mirrors - tcpdump/commitdiff
LISP: don't decrement count variables unless we know they're not zero.
authorGuy Harris <[email protected]>
Tue, 16 Nov 2021 00:44:46 +0000 (16:44 -0800)
committerGuy Harris <[email protected]>
Sat, 19 Mar 2022 23:27:08 +0000 (16:27 -0700)
This fixes some undefined behavior warnings.

(cherry picked from commit 913a9fa71293ce12b3c1dea3d93d3a97cf685625)

print-lisp.c

index 0012e06eea15b09290ab368dc149555fd2a334a7..756fff0ffc5a7392eed749b7ffea684636b9cc86 100644 (file)
@@ -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);