]> The Tcpdump Group git mirrors - libpcap/commit
gencode: Fix an undefined behavior in gen_mcode()
authorFrancois-Xavier Le Bail <[email protected]>
Mon, 16 Dec 2024 13:28:26 +0000 (14:28 +0100)
committerfxlb <[email protected]>
Tue, 17 Dec 2024 18:57:35 +0000 (18:57 +0000)
commita7a0738de08622b523a3031be688d6c5280aa810
treeb9e7dafa1c416bc78cc6652718b6c72ce80f05ea
parenta72770a124511fb85bd76821940ebe49524e4401
gencode: Fix an undefined behavior in gen_mcode()

Use a temporary 64-bit variable for the shift result.

Netmask length 0 is no longer a special case.

The error was:

$ testprogs/filtertest EN10MB net 192.168.0.0/16
gencode.c:7446:19: runtime error: left shift of 4294967295 by 16 places
  cannot be represented in type 'unsigned int'

SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior gencode.c:7446:19

$ testprogs/filtertest EN10MB net 10.0.1.0/24
gencode.c:7446:19: runtime error: left shift of 4294967295 by 8 places
  cannot be represented in type 'unsigned int'

SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior gencode.c:7446:19
gencode.c