Fix is_valid_ip() to only accept literal IPv4 addresses

`NetAddr::IP` will call `gethostbyname` if the argument is not a
literal IP address, and hence try to do DNS resolving on it. Cute,
but not relevant here, and not fully functional, since a host name
with a `-` in it would have been split as a range in `asctl`.
This commit is contained in:
Steven Bakker 2021-05-06 17:37:58 +02:00
parent ef1bf30e86
commit 675fdb9711

View File

@ -466,10 +466,11 @@ sub is_valid_bool {
###############################################################################
=item X<is_valid_ip>B<is_valid_ip> ( I<ARG>
=item B<is_valid_ip> ( I<ARG>
[, B<-network> =E<gt> I<CIDR>]
[, B<-err> =E<gt> I<REF>]
)
X<is_valid_ip>
Check whether I<ARG> is defined and represents a valid IPv4 address.
If I<CIDR> is given, it also checks whether the address is part
@ -491,7 +492,7 @@ sub is_valid_ip {
return;
}
my $ip = NetAddr::IP->new($arg);
my $ip = $arg =~ /^\d/ ? NetAddr::IP->new($arg) : undef;
if (!$ip) {
${$opts{-err}} = qq/"$arg" is not a valid IPv4 address/;
return;