]> git.ipfire.org Git - thirdparty/sarg.git/commitdiff
Fix the aliasing of an IPv4 address
authorFrederic Marchal <fmarchal@users.sourceforge.net>
Thu, 6 Jun 2013 12:22:39 +0000 (14:22 +0200)
committerFrederic Marchal <fmarchal@users.sourceforge.net>
Thu, 6 Jun 2013 12:22:39 +0000 (14:22 +0200)
The comparison was not working properly and the line of code was a little
bit obfuscated.

alias.c

diff --git a/alias.c b/alias.c
index 22a1b2e91d6fd5ffd4484e23bebfcac8f523ae27..c3d31ad9c6cf33228a7be1ee1bab2c3d4c2aaa0d 100644 (file)
--- a/alias.c
+++ b/alias.c
@@ -711,12 +711,14 @@ Replace the IPv4 address by its alias if it is in our list.
 static bool Alias_MatchIpv4(struct AliasItemStruct *alias,unsigned char *ipv4)
 {
        int len;
+       int n,m;
 
        len=alias->Ipv4.NBits;
-       if ((len<8 || memcmp(ipv4,alias->Ipv4.Ip,len/8)==0) && ((len%8)==0 || (ipv4[len/8] ^ alias->Ipv4.Ip[len/8]) & (0xFFU<<(8-len%8)))==0) {
-               return(true);
-       }
-       return(false);
+       n=len/8;
+       m=len%8;
+       if (n>0 && memcmp(ipv4,alias->Ipv4.Ip,n)!=0) return(false);
+       if (m!=0 && (ipv4[n] ^ alias->Ipv4.Ip[n]) & (0xFFU<<(8-m))!=0) return(false);
+       return(true);
 }
 
 /*!