]> The Tcpdump Group git mirrors - tcpdump/commitdiff
DVMRP: Fix an undefined behavior at runtime
authorFrancois-Xavier Le Bail <[email protected]>
Sun, 8 Jul 2018 13:03:45 +0000 (15:03 +0200)
committerFrancois-Xavier Le Bail <[email protected]>
Sun, 8 Jul 2018 13:03:45 +0000 (15:03 +0200)
Found with -fsanitize=undefined clang compiler option.

The error was:
print-dvmrp.c:238:27: runtime error: left shift of 240 by 24 places cannot
be represented in type 'int'

print-dvmrp.c

index c4efd0a5a2c4896961933bed07c56694ab20d3a1..983b63b467725817d3cc53fb285f8e034431d2f6 100644 (file)
@@ -235,8 +235,7 @@ print_probe(netdissect_options *ndo,
                ND_PRINT(" [|}");
                return (0);
        }
                ND_PRINT(" [|}");
                return (0);
        }
-       genid = (EXTRACT_U_1(bp) << 24) | (EXTRACT_U_1(bp + 1) << 16) |
-                (EXTRACT_U_1(bp + 2) << 8) | EXTRACT_U_1(bp + 3);
+       genid = EXTRACT_BE_U_4(bp);
        bp += 4;
        len -= 4;
        ND_PRINT(ndo->ndo_vflag > 1 ? "\n\t" : " ");
        bp += 4;
        len -= 4;
        ND_PRINT(ndo->ndo_vflag > 1 ? "\n\t" : " ");