summary refs log tree commit diff
path: root/lib/LWPx
diff options
context:
space:
mode:
Diffstat (limited to 'lib/LWPx')
-rw-r--r--lib/LWPx/ParanoidAgent.pm7
1 files changed, 5 insertions, 2 deletions
diff --git a/lib/LWPx/ParanoidAgent.pm b/lib/LWPx/ParanoidAgent.pm
index 0db4380..bc2669b 100644
--- a/lib/LWPx/ParanoidAgent.pm
+++ b/lib/LWPx/ParanoidAgent.pm
@@ -137,6 +137,8 @@ sub _bad_host {
 
     my $addr;  # network order packed IP address
 
+    return 0 if ((not @parts) || (@parts > 4));
+
     if (@parts == 1) {
         # a - 32 bits
         return 1 if
@@ -196,8 +198,9 @@ sub request {
     $first_res = $first_res->previous while $first_res && $first_res->previous;
     $req->{_time_begin} = $first_res ? $first_res->request->{_time_begin} : time();
 
-    my $host = $req->uri->host;
-    if ($self->_bad_host($host)) {
+    my $host;
+    eval { $host = $req->uri->host };
+    if ($@ || !$host || $self->_bad_host($host)) {
         my $err_res = HTTP::Response->new(403, "Unauthorized access to blocked host");
         $err_res->request($req);
         $err_res->header("Client-Date" => HTTP::Date::time2str(time));