libspf2 IPv6 patch

Ole Hansen <[email protected]> Sun, 27 Sep 2009 00:21:45 -0400
Newsgroups gmane.mail.spam.spf.devel
Message-ID <[email protected]>
This is a multi-part message in MIME format.
--------------050301030809070806060403
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit

Hello,

I just saw that one is supposed to use this list for contacting the 
libspf2 developer(s). I already sent this to Shevek a few days ago, so 
sorry if it's a duplicate ... :

I recently tested libspf2 with IPv6 email (I know, I'm a very early 
adopter...) and ran into problems. I tracked it down to a typo in the 
declaration of a char array. If an SPF record had an "ip6:" mechanism, 
the specified address would get truncated when the record was compiled 
(unless it happened to be shorter than 16 chars).

A patch is attached.  The patch also fixes an unrelated bug with 
printing debug message.

Just thought I'd contribute this in hopes it makes it into the 
distribution eventually.

Regards,
Ole Hansen




--------------050301030809070806060403
Content-Type: text/plain;
 name="libspf2-1.2.9-ipv6.patch"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
 filename="libspf2-1.2.9-ipv6.patch"

--- libspf2-1.2.9-orig/src/libspf2/spf_compile.c	2008-11-03 15:37:33.000000000 -0500
+++ libspf2-1.2.9/src/libspf2/spf_compile.c	2009-09-07 23:46:02.000000000 -0400
@@ -778,7 +778,7 @@
 	const char			*end;
 	const char			*p;
 
-	char				 buf[ INET_ADDRSTRLEN ];
+	char				 buf[ INET6_ADDRSTRLEN ];
 	size_t				 len;
 	int					 err;
 
--- libspf2-1.2.9-orig/src/libspf2/spf_interpret.c	2008-10-22 11:47:43.000000000 -0400
+++ libspf2-1.2.9/src/libspf2/spf_interpret.c	2009-09-08 00:42:25.000000000 -0400
@@ -505,7 +505,7 @@
 	char		dst_ip6_buf[ INET6_ADDRSTRLEN ];
 
 	struct in6_addr		src_ipv6;
-	int				cidr, mask;
+	int				cidr, cidr_save, mask;
 	int				i;
 	int				match;
 
@@ -517,6 +517,7 @@
 	cidr = SPF_i_mech_cidr(spf_request, mech);
 	if ( cidr == 0 )
 		cidr = 128;
+	cidr_save = cidr;
 
 	match = TRUE;
 	for( i = 0; i < array_elem( ipv6.s6_addr ) && match; i++ )
@@ -538,7 +539,7 @@
 		INET_NTOP(AF_INET6, &ipv6.s6_addr,
 							dst_ip6_buf, sizeof(dst_ip6_buf));
 		SPF_debugf( "ip_match:  %s == %s  (/%d):  %d",
-				src_ip6_buf, dst_ip6_buf, cidr, match );
+				src_ip6_buf, dst_ip6_buf, cidr_save, match );
 	}
 
 	return match;