You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@spamassassin.apache.org by fe...@apache.org on 2006/07/29 03:49:11 UTC

svn commit: r426739 - in /spamassassin/trunk: lib/Mail/SpamAssassin/Util.pm t/uri.t

Author: felicity
Date: Fri Jul 28 18:49:11 2006
New Revision: 426739

URL: http://svn.apache.org/viewvc?rev=426739&view=rev
Log:
bug 5013: handle more IP obfuscation, add in tests, etc.

Modified:
    spamassassin/trunk/lib/Mail/SpamAssassin/Util.pm
    spamassassin/trunk/t/uri.t

Modified: spamassassin/trunk/lib/Mail/SpamAssassin/Util.pm
URL: http://svn.apache.org/viewvc/spamassassin/trunk/lib/Mail/SpamAssassin/Util.pm?rev=426739&r1=426738&r2=426739&view=diff
==============================================================================
--- spamassassin/trunk/lib/Mail/SpamAssassin/Util.pm (original)
+++ spamassassin/trunk/lib/Mail/SpamAssassin/Util.pm Fri Jul 28 18:49:11 2006
@@ -1141,11 +1141,22 @@
 
       ########################
 
-      # deal with 'http://213.172.0x1f.13/', decode encoded octets
-      if ($host =~ /^([0-9a-fx]*\.)([0-9a-fx]*\.)([0-9a-fx]*\.)([0-9a-fx]*)$/ix) {
-        my (@chunk) = ($1,$2,$3,$4);
-        for my $octet (0 .. 3) {
-          $chunk[$octet] =~ s/^0x([0-9a-f][0-9a-f])/sprintf "%d",hex($1)/gei;
+      # deal with hosts which are IPs
+      # also handle things like:
+      # http://89.0x00000000000000000000068.0000000000000000000000160.0x00000000000011
+      #    both hex (0x) and oct (0+) encoded octets, etc.
+
+      if ($host =~ /^
+        ((?:0x[0-9a-f]{2,}|\d+)\.)
+	((?:0x[0-9a-f]{2,}|\d+)\.)
+	((?:0x[0-9a-f]{2,}|\d+)\.)
+	(0x[0-9a-f]{2,}|\d+)
+	$/ix) {
+        my @chunk = ($1,$2,$3,$4);
+        foreach my $octet (@chunk) {
+          $octet =~ s/^0x0*([0-9a-f][0-9a-f])/sprintf "%d",hex($1)/gei;
+          $octet =~ s/^0+([1-3][0-7]{0,2}|[4-7][0-7]?)\b/sprintf "%d",oct($1)/ge;
+	  $octet =~ s/^0+//;
         }
         push(@nuris, join ('', $proto, @chunk, $rest));
       }

Modified: spamassassin/trunk/t/uri.t
URL: http://svn.apache.org/viewvc/spamassassin/trunk/t/uri.t?rev=426739&r1=426738&r2=426739&view=diff
==============================================================================
--- spamassassin/trunk/t/uri.t (original)
+++ spamassassin/trunk/t/uri.t Fri Jul 28 18:49:11 2006
@@ -23,7 +23,7 @@
 use Mail::SpamAssassin::HTML;
 use Mail::SpamAssassin::Util;
 
-plan tests => 84;
+plan tests => 88;
 
 ##############################################
 
@@ -206,6 +206,35 @@
    'http://65.26.26.95:/https-www.paypal.com/webscrr/index.php',
    'http://www.google.com/pagead/iclk?sa=l&ai=Br3ycNQz5Q-fXBJGSiQLU0eDSAueHkArnhtWZAu-FmQWgjlkQAxgFKAg4AEDKEUiFOVD-4r2f-P____8BoAGyqor_A8gBAZUCCapCCqkCxU7NLQH0sz4&num=5&adurl=http://1092229727:/https-www.paypal.com/webscrr/index.php',
    ]));
+
+ok(try_canon([
+   'http://89.0x00000000000000000000068.0000000000000000000000160.0x00000000000011'
+   ], [
+   'http://89.0x00000000000000000000068.0000000000000000000000160.0x00000000000011',
+   'http://89.104.112.17',
+   ]));
+
+ok(try_canon([
+   'http://0x000000059.104.00000000000160.0x00011'
+   ], [
+   'http://0x000000059.104.00000000000160.0x00011',
+   'http://89.104.112.17',
+   ]));
+
+ok(try_canon([
+   'http://089.104.0160.0x11',
+   ], [
+   'http://089.104.0160.0x11',
+   'http://89.104.112.17',
+   ]));
+
+ok(try_canon([
+   'http://0x7f000001',
+   ], [
+   'http://0x7f000001',
+   'http://127.0.0.1',
+   ]));
+
 
 ##############################################