]> The Tcpdump Group git mirrors - tcpdump/blobdiff - print-cdp.c
CDP: Fix two loops for undefined behavior at runtime
[tcpdump] / print-cdp.c
index 79d7046c7367c0ca41b72bf1c7ae25fe23655f35..e63ce9118cbf3c6ac1fe800f7ac2d2e337c0b9fc 100644 (file)
@@ -360,9 +360,10 @@ cdp_print_addr(netdissect_options *ndo,
                        if (p + pl > endp)
                                goto trunc;
                        ND_PRINT("pt=0x%02x, pl=%u, pb=", EXTRACT_U_1((p - 2)), pl);
-                       while (pl-- > 0) {
+                       while (pl != 0) {
                                ND_PRINT(" %02x", EXTRACT_U_1(p));
                                p++;
+                               pl--;
                        }
                        ND_TCHECK_2(p);
                        if (p + 2 > endp)
@@ -372,9 +373,10 @@ cdp_print_addr(netdissect_options *ndo,
                        ND_TCHECK_LEN(p, al);
                        if (p + al > endp)
                                goto trunc;
-                       while (al-- > 0) {
+                       while (al != 0) {
                                ND_PRINT(" %02x", EXTRACT_U_1(p));
                                p++;
+                               al--;
                        }
                }
                num--;