]> git.ipfire.org Git - thirdparty/sarg.git/commitdiff
Take the port number into account when processing IPv4 addresses
authorFrédéric Marchal <fmarchal@users.sourceforge.net>
Mon, 21 May 2012 08:10:37 +0000 (10:10 +0200)
committerFrédéric Marchal <fmarchal@users.sourceforge.net>
Mon, 21 May 2012 08:10:37 +0000 (10:10 +0200)
The port number is ignored from IPv4 addresses read from the log file. It
allows to compare IPv4 addresses against the host exclusion list.

Prior to that change, it was not possible to filter out IPv4 ranges if a
port number was reported in the log file as the address was not recognized
as an IPv4 address and therefore was not compared to the correct exclusion
list.

Thanks to Mark Easter for reporting this bug.

ChangeLog
util.c

index 32281e0d7c48cccc853bfdeacc2a58f4192d89a5..f1e86586ca43e283e5601bdec7935d47af7fb0b5 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,6 +1,6 @@
 SARG ChangeLog
 
-Feb-13-2011 Version 2.3.3-pre1
+May-21-2012 Version 2.3.3-pre1
                - Don't abort the report generation due to an error in a squidGuard error (wrapped over log lines).
                - Support for gd, ldap and iconv can be disabled during configuration.
                - Suppress the blank line breaking the header of the e-mail report.
@@ -8,6 +8,7 @@ Feb-13-2011 Version 2.3.3-pre1
                - Fix the report generation if users_sites is disabled.
                - Avoid a possible name clash among the temporary files if a user happen to have the same name as one of the files sarg generates.
                - Accept regular expressions in the hostalias file.
+               - Exclude hosts based on the IPv4 address even if a port number is suffixed after the IP address. (thanks to Mark Easter for reporting the bug).
 
 Dec-07-2011 Version 2.3.2
                - Add support for sorttable.js (http://www.kryogenix.org/code/browser/sorttable/) to dynamically sort some tables (thanks to Éric).
diff --git a/util.c b/util.c
index 1891b755b75c17ca8bc6996716403516443d05a4..419c3e68529c2b367e5847c119ac9375d8e3eb45 100644 (file)
--- a/util.c
+++ b/util.c
@@ -1880,7 +1880,9 @@ int extract_address_mask(const char *buf,const char **text,unsigned char *ipv4,u
        int mask, max_mask;
        int pad_pos;
        int pad_len;
-       int bracket=false;
+       bool bracket=false;
+       bool port=false;
+       bool port_num=0;
 
        // skip leading spaces and tabs
        while (*buf && (*buf==' ' || *buf=='\t')) buf++;
@@ -1900,11 +1902,18 @@ int extract_address_mask(const char *buf,const char **text,unsigned char *ipv4,u
        for (i=0 ; (unsigned char)buf[i]>' ' && buf[i]!='/' && buf[i]!='?' && (!bracket || buf[i]!=']') && ip_size ; i++) {
                if (ip_size & 0x04) {
                        if (isdigit(buf[i])) {
-                               value4=value4*10+(buf[i]-'0');
-                               if (value4>0xFFU) ip_size&=~0x04;
+                               if (port) {
+                                       port_num=port_num*10+(buf[i]-'0');
+                                       if (port_num>65535) ip_size&=~0x04;
+                               } else {
+                                       value4=value4*10+(buf[i]-'0');
+                                       if (value4>0xFFU) ip_size&=~0x04;
+                               }
                        } else if (buf[i]=='.' && addr_len<4) {
                                addr[addr_len++]=(unsigned short)(value4 & 0xFFU);
                                value4=0U;
+                       } else if (!port && buf[i]==':') {
+                               port=true;
                        } else {
                                ip_size&=~0x04;
                        }