From 08eb52bb7c3643948a70d52d2fff92c7ce64a785 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Fr=C3=A9d=C3=A9ric=20Marchal?= Date: Mon, 21 May 2012 10:10:37 +0200 Subject: [PATCH] Take the port number into account when processing IPv4 addresses 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 | 3 ++- util.c | 15 ++++++++++++--- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/ChangeLog b/ChangeLog index 32281e0..f1e8658 100644 --- 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 1891b75..419c3e6 100644 --- 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; } -- 2.47.2