From 23b5624575df7b1ebc587281b6d912271e3f65af Mon Sep 17 00:00:00 2001 From: Damien PIQUET Date: Sat, 23 Feb 2013 12:21:09 +0100 Subject: [PATCH] Modified IPv4 validation function, included Net::IP Signed-off-by: Damien PIQUET --- data/PVE/JSONSchema.pm | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/data/PVE/JSONSchema.pm b/data/PVE/JSONSchema.pm index 4b33646..6866f18 100644 --- a/data/PVE/JSONSchema.pm +++ b/data/PVE/JSONSchema.pm @@ -8,6 +8,7 @@ use Devel::Cycle -quiet; # todo: remove? use PVE::Tools qw(split_list); use PVE::Exception qw(raise); use HTTP::Status qw(:constants); +use Net::IP qw(:PROC); use base 'Exporter'; @@ -140,11 +141,8 @@ register_format('ipv4', \&pve_verify_ipv4); sub pve_verify_ipv4 { my ($ipv4, $noerr) = @_; - if ($ipv4 !~ m/^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/ || - !(($1 > 0) && ($1 < 255) && - ($2 <= 255) && ($3 <= 255) && - ($4 > 0) && ($4 < 255))) { - return undef if $noerr; + if (!Net::IP::ip_is_ipv4($ipv4)) { + return undef if $noerr; die "value does not look like a valid IP address\n"; } return $ipv4; -- 2.39.2