fixed loop termination criterion in addr_in_subnet(). Thanks go to Wolfgang Steudel...
authorAndreas Steffen <andreas.steffen@strongswan.org>
Tue, 7 Oct 2008 21:41:45 +0000 (21:41 -0000)
committerAndreas Steffen <andreas.steffen@strongswan.org>
Tue, 7 Oct 2008 21:41:45 +0000 (21:41 -0000)
src/charon/plugins/kernel_netlink/kernel_netlink_net.c

index f147762..6e1489c 100644 (file)
@@ -698,14 +698,16 @@ static bool addr_in_subnet(chunk_t addr, chunk_t net, int net_len)
        /* scan through all bits, beginning in the front */
        for (byte = 0; byte < addr.len; byte++)
        {
        /* scan through all bits, beginning in the front */
        for (byte = 0; byte < addr.len; byte++)
        {
-               for (bit = 7; bit >= 0; bit--)
+               for (bit = 0; bit < 8; bit++)
                {
                {
+                       u_char bitpos = 1 << (7-bit);
+
                        /* check if bits are equal (or we reached the end of the net) */
                        if (bit + byte * 8 > net_len)
                        {
                                return TRUE;
                        }
                        /* check if bits are equal (or we reached the end of the net) */
                        if (bit + byte * 8 > net_len)
                        {
                                return TRUE;
                        }
-                       if (((1<<bit) & addr.ptr[byte]) != ((1<<bit) & net.ptr[byte]))
+                       if ((bitpos & addr.ptr[byte]) != (bitpos & net.ptr[byte]))
                        {
                                return FALSE;
                        }
                        {
                                return FALSE;
                        }