]> The Tcpdump Group git mirrors - tcpdump/commitdiff
CDP: Fix two loops for undefined behavior at runtime
authorFrancois-Xavier Le Bail <[email protected]>
Sun, 17 Mar 2019 14:01:15 +0000 (15:01 +0100)
committerFrancois-Xavier Le Bail <[email protected]>
Sun, 17 Mar 2019 14:01:15 +0000 (15:01 +0100)
The errors were:
print-cdp.c:363:13: runtime error: unsigned integer overflow: 0 - 1
cannot be represented in type 'u_int' (aka 'unsigned int')
print-cdp.c:375:13: runtime error: unsigned integer overflow: 0 - 1
cannot be represented in type 'u_int' (aka 'unsigned int')

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--;