spamassassin-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From d..@apache.org
Subject svn commit: r374643 - in /spamassassin/trunk: lib/Mail/SpamAssassin/Constants.pm t/ip_addrs.t
Date Fri, 03 Feb 2006 11:54:40 GMT
Author: dos
Date: Fri Feb  3 03:54:36 2006
New Revision: 374643

URL: http://svn.apache.org/viewcvs?rev=374643&view=rev
Log:
bug 4780: fix IP_ADDRESS & LOCALHOST regexes to correctly parse IPv6 addresses

Modified:
    spamassassin/trunk/lib/Mail/SpamAssassin/Constants.pm
    spamassassin/trunk/t/ip_addrs.t

Modified: spamassassin/trunk/lib/Mail/SpamAssassin/Constants.pm
URL: http://svn.apache.org/viewcvs/spamassassin/trunk/lib/Mail/SpamAssassin/Constants.pm?rev=374643&r1=374642&r2=374643&view=diff
==============================================================================
--- spamassassin/trunk/lib/Mail/SpamAssassin/Constants.pm (original)
+++ spamassassin/trunk/lib/Mail/SpamAssassin/Constants.pm Fri Feb  3 03:54:36 2006
@@ -96,15 +96,66 @@
 		      # plain IPv4
 		      127\.0\.0\.1 \b
 		    |
-		      # IPv4 mapped in IPv6
-		      0{0,4} : (?:0{0,4}\:){1,2} ffff: 
-		      127\.0\.0\.1 \b
-		    |
-		      # pure-IPv6 address
+		      # IPv6 addresses
+		      # don't use \b here, it hits on :'s
 		      (?:IPv6:    # with optional prefix
-                        | (?<!:)
+                        | (?<![a-f0-9:])
                       )
-		      (?:0{0,4}\:){0,7} 1 
+		      (?:
+			# IPv4 mapped in IPv6
+			# note the colon after the 12th byte in each here
+			(?:
+			  # first 6 (12 bytes) non-zero
+			  (?:0{1,4}:){5}		ffff:
+			  |
+			  # leading zeros omitted (note {0,5} not {1,5})
+			  ::(?:0{1,4}:){0,4}		ffff:
+			  |
+			  # trailing zeros (in the first 6) omitted
+			  (?:0{1,4}:){1,4}:		ffff:
+			  |
+			  # 0000 in second up to (including) fifth omitted
+			  0{1,4}::(?:0{1,4}:){1,3}	ffff:
+			  |
+			  # 0000 in third up to (including) fifth omitted
+			  (?:0{1,4}:){2}:0{1,2}:	ffff:
+			  |
+			  # 0000 in fourth up to (including) fifth omitted
+			  (?:0{1,4}:){3}:0:		ffff:
+			  |
+			  # 0000 in fifth omitted
+			  (?:0{1,4}:){4}:		ffff:
+			)
+			# and the IPv4 address appended to all of the 12 bytes above
+			127\.0\.0\.1	# no \b, we check later
+
+			| # or (separately) a pure IPv6 address
+
+			# all 8 (16 bytes) of them present
+			(?:0{1,4}:){7}			0{0,3}1
+			|
+			# leading zeros omitted
+			:(?::0{1,4}){0,6}:		0{0,3}1
+			|
+			# 0000 in second up to (including) seventh omitted
+			0{1,4}:(?::0{1,4}){0,5}:	0{0,3}1
+			|
+			# 0000 in third up to (including) seventh omitted
+			(?:0{1,4}:){2}(?::0{1,4}){0,4}:	0{0,3}1
+			|
+			# 0000 in fouth up to (including) seventh omiited
+			(?:0{1,4}:){3}(?::0{1,4}){0,3}:	0{0,3}1
+			|
+			# 0000 in fifth up to (including) seventh omitted
+			(?:0{1,4}:){4}(?::0{1,4}){0,2}:	0{0,3}1
+			|
+			# 0000 in sixth up to (including) seventh omitted
+			(?:0{1,4}:){5}(?::0{1,4}){0,1}:	0{0,3}1
+			|
+			# 0000 in seventh omitted
+			(?:0{1,4}:){6}:			0{0,3}1
+		      )
+		      (?![a-f0-9:])
 		    )
 		  /oxi;
 
@@ -131,19 +182,78 @@
 		      (?:1\d\d|2[0-4]\d|25[0-5]|\d\d|\d)\.
 		      (?:1\d\d|2[0-4]\d|25[0-5]|\d\d|\d)\b
 		    |
-		      # IPv4 mapped in IPv6
-		      \:\: (?:[a-f0-9]{0,4}\:){0,4}
-		      (?:1\d\d|2[0-4]\d|25[0-5]|\d\d|\d)\.
-		      (?:1\d\d|2[0-4]\d|25[0-5]|\d\d|\d)\.
-		      (?:1\d\d|2[0-4]\d|25[0-5]|\d\d|\d)\.
-		      (?:1\d\d|2[0-4]\d|25[0-5]|\d\d|\d)\b
-		    |
-		      # a pure-IPv6 address
+		      # IPv6 addresses
 		      # don't use \b here, it hits on :'s
 		      (?:IPv6:    # with optional prefix
-                        | (?<!:)
+                        | (?<![a-f0-9:])
                       )
-		      (?:[a-f0-9]{0,4}\:){0,7} [a-f0-9]{0,4}
+		      (?:
+			# IPv4 mapped in IPv6
+			# note the colon after the 12th byte in each here
+			(?:
+			  # first 6 (12 bytes) non-zero
+			  (?:[a-f0-9]{1,4}:){6}
+			  |
+			  # leading zeros omitted (note {0,5} not {1,5})
+			  ::(?:[a-f0-9]{1,4}:){0,5}
+			  |
+			  # trailing zeros (in the first 6) omitted
+			  (?:[a-f0-9]{1,4}:){1,5}:
+			  |
+			  # 0000 in second up to (including) fifth omitted
+			  [a-f0-9]{1,4}::(?:[a-f0-9]{1,4}:){1,4}
+			  |
+			  # 0000 in third up to (including) fifth omitted
+			  (?:[a-f0-9]{1,4}:){2}:(?:[a-f0-9]{1,4}:){1,3}
+			  |
+			  # 0000 in fourth up to (including) fifth omitted
+			  (?:[a-f0-9]{1,4}:){3}:(?:[a-f0-9]{1,4}:){1,2}
+			  |
+			  # 0000 in fifth omitted
+			  (?:[a-f0-9]{1,4}:){4}:[a-f0-9]{1,4}:
+			)
+			# and the IPv4 address appended to all of the 12 bytes above
+			(?:1\d\d|2[0-4]\d|25[0-5]|\d\d|\d)\.
+			(?:1\d\d|2[0-4]\d|25[0-5]|\d\d|\d)\.
+			(?:1\d\d|2[0-4]\d|25[0-5]|\d\d|\d)\.
+			(?:1\d\d|2[0-4]\d|25[0-5]|\d\d|\d)   # no \b, we check later
+
+			| # or (separately) a pure IPv6 address
+
+			# all 8 (16 bytes) of them present
+			(?:[a-f0-9]{1,4}:){7}[a-f0-9]{1,4}
+			|
+			# leading zeros omitted
+			:(?::[a-f0-9]{1,4}){1,7}
+			|
+			# trailing zeros omitted
+			(?:[a-f0-9]{1,4}:){1,7}:
+			|
+			# 0000 in second up to (including) seventh omitted
+			[a-f0-9]{1,4}:(?::[a-f0-9]{1,4}){1,6}
+			|
+			# 0000 in third up to (including) seventh omitted
+			(?:[a-f0-9]{1,4}:){2}(?::[a-f0-9]{1,4}){1,5}
+			|
+			# 0000 in fouth up to (including) seventh omiited
+			(?:[a-f0-9]{1,4}:){3}(?::[a-f0-9]{1,4}){1,4}
+			|
+			# 0000 in fifth up to (including) seventh omitted
+			(?:[a-f0-9]{1,4}:){4}(?::[a-f0-9]{1,4}){1,3}
+			|
+			# 0000 in sixth up to (including) seventh omitted
+			(?:[a-f0-9]{1,4}:){5}(?::[a-f0-9]{1,4}){1,2}
+			|
+			# 0000 in seventh omitted
+			(?:[a-f0-9]{1,4}:){6}:[a-f0-9]{1,4}
+			|
+			# :: (the unspecified addreess 0:0:0:0:0:0:0:0)
+			# dos: I don't expect to see this address in a header, and
+			# it may cause non-address strings to match, but we'll
+			# include it for now since it is valid
+			::
+		      )
+		      (?![a-f0-9:])
 		    )
 		  /oxi;
 

Modified: spamassassin/trunk/t/ip_addrs.t
URL: http://svn.apache.org/viewcvs/spamassassin/trunk/t/ip_addrs.t?rev=374643&r1=374642&r2=374643&view=diff
==============================================================================
--- spamassassin/trunk/t/ip_addrs.t (original)
+++ spamassassin/trunk/t/ip_addrs.t Fri Feb  3 03:54:36 2006
@@ -26,7 +26,7 @@
     rules_filename => "$prefix/rules",
 });
 
-plan tests => 71;
+plan tests => 77;
 
 sub tryone {
   my ($pat, $testip) = @_;
@@ -77,8 +77,8 @@
 ok (!tryone (Mail::SpamAssassin::Constants::IP_ADDRESS, "FEDC:BA98:7654:3210:FEDC:BA98:7654:3210:"));
 ok (!tryone (Mail::SpamAssassin::Constants::IP_ADDRESS, "FEDC:BA98:7654:3210:FEDC:BA98:7654:3210:9348"));
 ok (!tryone (Mail::SpamAssassin::Constants::IP_ADDRESS, "3ffe:fffff:100:f101:210:a4ff:fee3:9566"));
-ok (tryone (Mail::SpamAssassin::Constants::IP_ADDRESS, "ff02:0:0:0:0:0:1"));
-ok (tryone (Mail::SpamAssassin::Constants::IP_ADDRESS, "ff02:0:0:0:0:0:2"));
+ok (tryone (Mail::SpamAssassin::Constants::IP_ADDRESS, "ff02:0:0:0:0:0:0:1"));
+ok (tryone (Mail::SpamAssassin::Constants::IP_ADDRESS, "ff02:0:0:0:0:0:0:2"));
 ok (tryone (Mail::SpamAssassin::Constants::IP_ADDRESS, "IPv6:::1"));
 ok (tryone (Mail::SpamAssassin::Constants::IP_ADDRESS, "IPv6:3ffe:2500:310:3:20a:95ff:fef5:246e"));
 
@@ -86,8 +86,9 @@
 ok (tryone (Mail::SpamAssassin::Constants::LOCALHOST, "localhost.localdomain"));
 ok (tryone (Mail::SpamAssassin::Constants::LOCALHOST, "127.0.0.1"));
 ok (tryone (Mail::SpamAssassin::Constants::LOCALHOST, "::ffff:127.0.0.1"));
-ok (tryone (Mail::SpamAssassin::Constants::LOCALHOST, ":::ffff:127.0.0.1"));
-ok (tryone (Mail::SpamAssassin::Constants::LOCALHOST, "0000:0000:0000:ffff:127.0.0.1"));
+ok (!tryone (Mail::SpamAssassin::Constants::LOCALHOST, ":::ffff:127.0.0.1"));
+ok (!tryone (Mail::SpamAssassin::Constants::LOCALHOST, "0000:0000:0000:ffff:127.0.0.1"));
+ok (tryone (Mail::SpamAssassin::Constants::LOCALHOST, "0000:0000:0000:0000:0000:ffff:127.0.0.1"));
 ok (tryone (Mail::SpamAssassin::Constants::LOCALHOST, "::1"));
 ok (tryone (Mail::SpamAssassin::Constants::LOCALHOST, "0:0:0:0:0:0:0:1"));
 ok (!tryone (Mail::SpamAssassin::Constants::LOCALHOST, "3ffe:fffff:100:f101:210:a4ff:fee3:9566"));
@@ -95,6 +96,13 @@
 ok (!tryone (Mail::SpamAssassin::Constants::LOCALHOST, "notlocalhost"));
 ok (tryone (Mail::SpamAssassin::Constants::LOCALHOST, "IPv6:::1"));
 ok (!tryone (Mail::SpamAssassin::Constants::LOCALHOST, "IPv6:3ffe:2500:310:3:20a:95ff:fef5:246e"));
+
+ok (tryone (Mail::SpamAssassin::Constants::LOCALHOST, "::0:0:0:0:0:0:1"));
+ok (tryone (Mail::SpamAssassin::Constants::LOCALHOST, "::0:0:0:0:1"));
+ok (tryone (Mail::SpamAssassin::Constants::LOCALHOST, "0::0:0:0:0:0:1"));
+ok (tryone (Mail::SpamAssassin::Constants::LOCALHOST, "0:0::0:0:0:0:1"));
+ok (tryone (Mail::SpamAssassin::Constants::LOCALHOST, "0:0:0::0:0:1"));
+
 
 sub tsttrim {
   my $dom = shift;



Mime
View raw message