dovecot-1.0: allow_nets didn't work correctly with big endian ma...

dovecot at dovecot.org dovecot at dovecot.org
Thu May 15 08:34:57 EEST 2008


details:   http://hg.dovecot.org/dovecot-1.0/rev/71c02fdf1b59
changeset: 5551:71c02fdf1b59
user:      Timo Sirainen <tss at iki.fi>
date:      Thu May 15 08:34:53 2008 +0300
description:
allow_nets didn't work correctly with big endian machines.

diffstat:

1 file changed, 7 insertions(+), 5 deletions(-)
src/auth/auth-request.c |   12 +++++++-----

diffs (36 lines):

diff -r 3949304a8f8f -r 71c02fdf1b59 src/auth/auth-request.c
--- a/src/auth/auth-request.c	Fri May 09 19:05:38 2008 +0300
+++ b/src/auth/auth-request.c	Thu May 15 08:34:53 2008 +0300
@@ -825,7 +825,7 @@ static int is_ip_in_network(const char *
 	struct ip_addr src_ip, net_ip;
 	const char *p;
 	unsigned int max_bits, bits, pos, i;
-	uint32_t mask;
+	uint32_t mask, i1, i2;
 
 	if (net_ipv6_mapped_ipv4_convert(ip, &src_ip) == 0)
 		ip = &src_ip;
@@ -860,17 +860,19 @@ static int is_ip_in_network(const char *
 		if (ip1[i] != ip2[i])
 			return 0;
 	}
+	i1 = htonl(ip1[i]);
+	i2 = htonl(ip2[i]);
 
 	/* check the last full bytes */
-	for (mask = 0xff; pos + 8 <= bits; pos += 8, mask <<= 8) {
-		if ((ip1[i] & mask) != (ip2[i] & mask))
+	for (mask = 0xff000000; pos + 8 <= bits; pos += 8, mask >>= 8) {
+		if ((i1 & mask) != (i2 & mask))
 			return 0;
 	}
 
 	/* check the last bits, they're reversed in bytes */
 	bits -= pos;
-	for (mask = 0x80 << (pos % 32); bits > 0; bits--, mask >>= 1) {
-		if ((ip1[i] & mask) != (ip2[i] & mask))
+	for (mask = 0x80000000 >> (pos % 32); bits > 0; bits--, mask >>= 1) {
+		if ((i1 & mask) != (i2 & mask))
 			return 0;
 	}
 	return 1;


More information about the dovecot-cvs mailing list