Skip to content

Bug report: bad NextIP of "0.0.0.1" #783

@mars1024

Description

@mars1024

When I use

plugins/pkg/ip/cidr.go

Lines 23 to 26 in 7e9ada5

func NextIP(ip net.IP) net.IP {
i := ipToInt(ip)
return intToIP(i.Add(i, big.NewInt(1)))
}
to get next IP of address "0.0.0.1", I got an illegal result [2] but not an expected one [0,0,0,2].

This is because intToIP does not obey the byte length of IPv4(4)/IPv6(16) when first byte is 0.

plugins/pkg/ip/cidr.go

Lines 51 to 53 in 7e9ada5

func intToIP(i *big.Int) net.IP {
return net.IP(i.Bytes())
}

This bug will happen when first byte is 0 no matter family is IPv4 or IPv6.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions