Skip to content

nicutils.sh get_first_addr_ipv4 function should allow ip addr with final octet 0 #7507

@JDiprose

Description

@JDiprose

if [ $FIELD1 -gt 0 -a $FIELD1 -lt 255 -a $FIELD2 -le 255 -a $FIELD3 -le 255 -a $FIELD4 -le 255 -a $FIELD4 -gt 0 ]; then

I think the validation test on the final octet of the ip address ($FIELD4 -le 255 -a $FIELD4 -gt 0) is only actually valid for prefixes of /24 and higher (and doesn't cover all start-of-range cases for higher prefixes anyway). Certainly there are plenty of valid a.b.c.0 ip addresses within a /16.
Whilst I am looking at this line, according to https://www.iana.org/assignments/ipv4-address-space/ipv4-address-space.xml the first octet should be less than 224 (start of multicast and upper reserved range) as well as greater than zero. It probably shouldn't be 127 either.
So:

if [ $FIELD1 -gt 0 -a $FIELD1 -lt 255 -a $FIELD2 -le 255 -a $FIELD3 -le 255 -a $FIELD4 -le 255 -a $FIELD4 -gt 0 ]; then

should be

if [ $FIELD1 -gt 0 -a $FIELD1 -lt 224 -a $FIELD1 -ne 127 -a $FIELD2 -le 255 -a $FIELD3 -le 255 -a $FIELD4 -le 255 ]; then

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