Component
utils / network
Problem description
NetworkUtils.convertNetmask(Integer prefix) computes the mask with:
0xffffffff << (32 - prefix)
In Java, shifting an int by 32 is equivalent to shifting by 0. Therefore convertNetmask(0) returns 255.255.255.255 instead of the correct 0.0.0.0.
Relevant code:
https://github.com/ZSvirt/zsvirt/blob/main/utils/src/main/java/org/zstack/utils/network/NetworkUtils.java#L816-L829
This affects callers that compare or apply a valid IPv4 /0 configuration.
Steps to reproduce
Call NetworkUtils.convertNetmask(0).
Expected behavior
Return 0.0.0.0 for prefix 0. Prefixes outside the IPv4 range should be rejected explicitly.
Proposed fix
Handle prefix 0 before the shift and validate that the prefix is in [0, 32]. Add boundary tests for 0, 1, 24, and 32.
Component
utils / network
Problem description
NetworkUtils.convertNetmask(Integer prefix)computes the mask with:0xffffffff << (32 - prefix)In Java, shifting an
intby 32 is equivalent to shifting by 0. ThereforeconvertNetmask(0)returns255.255.255.255instead of the correct0.0.0.0.Relevant code:
https://github.com/ZSvirt/zsvirt/blob/main/utils/src/main/java/org/zstack/utils/network/NetworkUtils.java#L816-L829
This affects callers that compare or apply a valid IPv4
/0configuration.Steps to reproduce
Call
NetworkUtils.convertNetmask(0).Expected behavior
Return
0.0.0.0for prefix 0. Prefixes outside the IPv4 range should be rejected explicitly.Proposed fix
Handle prefix 0 before the shift and validate that the prefix is in
[0, 32]. Add boundary tests for 0, 1, 24, and 32.