--------------------- PatchSet 4709 Date: 2007/06/10 10:53:27 Author: amosjeffries Branch: squid3-ipv6 Tag: (none) Log: Fix error in ApplyMask(cidr) with non-specific protocol Members: lib/IPAddress.cc:1.1.2.46->1.1.2.47 lib/tests/testIPAddress.cc:1.1.2.10->1.1.2.11 Index: squid3/lib/IPAddress.cc =================================================================== RCS file: /cvsroot/squid-sf//squid3/lib/Attic/IPAddress.cc,v retrieving revision 1.1.2.46 retrieving revision 1.1.2.47 diff -u -r1.1.2.46 -r1.1.2.47 --- squid3/lib/IPAddress.cc 3 Jun 2007 12:14:42 -0000 1.1.2.46 +++ squid3/lib/IPAddress.cc 10 Jun 2007 10:53:27 -0000 1.1.2.47 @@ -1,6 +1,6 @@ /* - * $Id: IPAddress.cc,v 1.1.2.46 2007/06/03 12:14:42 amosjeffries Exp $ + * $Id: IPAddress.cc,v 1.1.2.47 2007/06/10 10:53:27 amosjeffries Exp $ * * DEBUG: section 14 IP Storage and Handling * AUTHOR: Amos Jeffries @@ -192,19 +192,28 @@ #if !USE_IPV6 assert(mtype != IPv6); /* using IPv6 in IPv4 is invalid. */ + + if(mtype == None) + mtype = IPv4; +#else + if(mtype == None) + mtype = IPv6; + #endif - if (cidr > 128 && mtype == IPv6) + // validation and short-cuts. + if (cidr > 128) return false; - - if (USE_IPV6 && cidr > 32 && mtype == IPv4) + + if (cidr > 32 && mtype == IPv4) return false; - if(cidr < 0) - return true; // any err like this can be assumed /0 - clearbits = (uint8_t)((mtype&IPv6?128:32)-cidr); + // short-cut + if(clearbits == 0) + return true; + #if USE_IPV6 p = (uint8_t*)(&m_SocketAddr.sin6_addr) + 15; Index: squid3/lib/tests/testIPAddress.cc =================================================================== RCS file: /cvsroot/squid-sf//squid3/lib/tests/Attic/testIPAddress.cc,v retrieving revision 1.1.2.10 retrieving revision 1.1.2.11 diff -u -r1.1.2.10 -r1.1.2.11 --- squid3/lib/tests/testIPAddress.cc 3 Jun 2007 12:14:45 -0000 1.1.2.10 +++ squid3/lib/tests/testIPAddress.cc 10 Jun 2007 10:53:28 -0000 1.1.2.11 @@ -489,6 +489,14 @@ /* Test Numeric ApplyCIDR */ anIPA.SetNoAddr(); + CPPUNIT_ASSERT( !anIPA.ApplyMask(129) ); +#if !USE_IPV6 + CPPUNIT_ASSERT( !anIPA.ApplyMask(33) ); +#endif + CPPUNIT_ASSERT( anIPA.ApplyMask(31) ); + CPPUNIT_ASSERT_EQUAL( 31 , anIPA.GetCIDR() ); + + anIPA.SetNoAddr(); anIPA.ApplyMask(31, IPv4); #if USE_IPV6 CPPUNIT_ASSERT_EQUAL( 127 , anIPA.GetCIDR() );