summary refs log tree commit diff
diff options
context:
space:
mode:
authorfranck cuny <franck@lumberjaph.net>2009-05-18 12:01:24 +0200
committerfranck cuny <franck@lumberjaph.net>2009-05-18 12:01:24 +0200
commit36fdcaa9f77f0a21f38bc638f52df37a90fa32d4 (patch)
treed616067319ec6796fadea191a43767d0e582f562
parentapplying patch by SREZIC http://rt.cpan.org/Public/Bug/Display.html?id=43471 (diff)
downloadlwpx-paranoidagent-36fdcaa9f77f0a21f38bc638f52df37a90fa32d4.tar.gz
patch rt #44391 and #44261
-rw-r--r--lib/LWPx/ParanoidAgent.pm7
-rwxr-xr-xt/00-all.t7
2 files changed, 11 insertions, 3 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));
diff --git a/t/00-all.t b/t/00-all.t
index eddfb7c..45477bd 100755
--- a/t/00-all.t
+++ b/t/00-all.t
@@ -4,7 +4,7 @@
 use strict;
 use LWPx::ParanoidAgent;
 use Time::HiRes qw(time);
-use Test::More tests => 29;
+use Test::More tests => 30;
 use Net::DNS;
 use IO::Socket::INET;
 
@@ -96,6 +96,11 @@ ok(! $res->is_success);
 like($res->status_line, qr/DNS lookup resulted in bad host/);
 $ua->resolver($old_resolver);
 
+# can't do empty host name
+$res = $ua->get('');
+print $res->status_line, "\n";
+ok(! $res->is_success);
+
 # black-listed via blocked_hosts
 $res = $ua->get("http://brad.lj/");
 print $res->status_line, "\n";