From: Vincent Pit Date: Sat, 10 Mar 2012 11:13:57 +0000 (+0100) Subject: Improve regexp validation in Xchat::XPI::Net::whois() X-Git-Url: http://git.vpit.fr/?a=commitdiff_plain;h=c47541f7a3aada1c0b4012a3cf16dee69eb3f9e3;p=perl%2Fscripts%2Fxchat.git Improve regexp validation in Xchat::XPI::Net::whois() --- diff --git a/Xchat/XPI/Net.pm b/Xchat/XPI/Net.pm index 9c83b14..96c4af3 100644 --- a/Xchat/XPI/Net.pm +++ b/Xchat/XPI/Net.pm @@ -62,16 +62,21 @@ my %whois_servers = ( ipv6 => { default => 'whois.6bone.net' }, ); +my $ipv4_rx = qr/[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}/; +my $ipv6_rx = qr/[0-9:]+/; + sub whois { my ($host, $callback, $args) = @_; return unless $host and $callback; my $server; - if ($host =~ /^\s*\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}(\/\d{1,2})?$/) { + if ($host =~ /^\s*($ipv4_rx)(?:\/[0-9]{1,2})?[\s\.]*$/o) { + $host = $1; $server = $whois_servers{ipv4}{default}; - } elsif ($host =~ /^\s*[\d:]*(\/\d{1,2})?\s*$/) { + } elsif ($host =~ /^\s*($ipv6_rx)(?:\/[0-9]{1,2})?[\s\.]*$/o) { + $host = $1; $server = $whois_servers{ipv6}{default}; - } elsif ($host =~ /([^\.]+)\.+([a-z]+)\.*$/) { + } elsif ($host =~ /([^\.]+)\.+([a-z]+)[\.\s]*$/) { $host = $1 . '.' . $2; $server = $whois_servers{domain}{$2}; $server = $whois_servers{domain}{default} unless $server;