From be74775e23ebdbfca900bef292fd4812144c647e Mon Sep 17 00:00:00 2001 From: Fabian Keil Date: Tue, 13 Mar 2007 11:28:43 +0000 Subject: [PATCH] - Fix port handling in acl_addr() and use a temporary acl spec copy so error messages don't contain a truncated version. - Log size of iob before and after decompression. --- filters.c | 48 +++++++++++++++++++++++++++++++++++++----------- filters.h | 8 ++++++-- 2 files changed, 43 insertions(+), 13 deletions(-) diff --git a/filters.c b/filters.c index 74b469d8..1c9b2544 100644 --- a/filters.c +++ b/filters.c @@ -1,4 +1,4 @@ -const char filters_rcs[] = "$Id: filters.c,v 1.80 2007/02/07 10:55:20 fabiankeil Exp $"; +const char filters_rcs[] = "$Id: filters.c,v 1.81 2007/03/05 14:40:53 fabiankeil Exp $"; /********************************************************************* * * File : $Source: /cvsroot/ijbswa/current/filters.c,v $ @@ -40,6 +40,11 @@ const char filters_rcs[] = "$Id: filters.c,v 1.80 2007/02/07 10:55:20 fabiankeil * * Revisions : * $Log: filters.c,v $ + * Revision 1.81 2007/03/05 14:40:53 fabiankeil + * - Cosmetical changes for LOG_LEVEL_RE_FILTER messages. + * - Hide the "Go there anyway" link for blocked CONNECT + * requests where going there anyway doesn't work anyway. + * * Revision 1.80 2007/02/07 10:55:20 fabiankeil * - Save the reason for generating http_responses. * - Block (+block) with status code 403 instead of 404. @@ -650,20 +655,33 @@ int block_acl(struct access_control_addr *dst, struct client_state *csp) * Returns : 0 => Ok, everything else is an error. * *********************************************************************/ -int acl_addr(char *aspec, struct access_control_addr *aca) +int acl_addr(const char *aspec, struct access_control_addr *aca) { - int i, masklength, port; + int i, masklength; + long port; char *p; + char *acl_spec = NULL; masklength = 32; port = 0; - if ((p = strchr(aspec, '/')) != NULL) + /* + * Use a temporary acl spec copy so we can log + * the unmodified original in case of parse errors. + */ + acl_spec = strdup(aspec); + if (acl_spec == NULL) { - *p++ = '\0'; + /* XXX: This will be logged as parse error. */ + return(-1); + } + if ((p = strchr(acl_spec, '/')) != NULL) + { + *p++ = '\0'; if (ijb_isdigit(*p) == 0) { + free(acl_spec); return(-1); } masklength = atoi(p); @@ -671,26 +689,32 @@ int acl_addr(char *aspec, struct access_control_addr *aca) if ((masklength < 0) || (masklength > 32)) { + free(acl_spec); return(-1); } - if ((p = strchr(aspec, ':')) != NULL) + if ((p = strchr(acl_spec, ':')) != NULL) { + char *endptr; + *p++ = '\0'; + port = strtol(p, &endptr, 10); - if (ijb_isdigit(*p) == 0) + if (port <= 0 || port > 65535 || *endptr != '\0') { + free(acl_spec); return(-1); } - port = atoi(p); } - aca->port = port; + aca->port = (unsigned long)port; - aca->addr = ntohl(resolve_hostname_to_ip(aspec)); + aca->addr = ntohl(resolve_hostname_to_ip(acl_spec)); + free(acl_spec); if (aca->addr == INADDR_NONE) { + /* XXX: This will be logged as parse error. */ return(-1); } @@ -1795,7 +1819,9 @@ char *pcrs_filter_response(struct client_state *csp) csp->content_type &= ~CT_DEFLATE; return(NULL); } - log_error(LOG_LEVEL_RE_FILTER, "Decompression successful"); + log_error(LOG_LEVEL_RE_FILTER, + "Decompression successful. Old size: %d, new size: %d.", + size, csp->iob->eod - csp->iob->cur); /* * Decompression gives us a completely new iob, diff --git a/filters.h b/filters.h index 702d99f6..f11f0a32 100644 --- a/filters.h +++ b/filters.h @@ -1,6 +1,6 @@ #ifndef FILTERS_H_INCLUDED #define FILTERS_H_INCLUDED -#define FILTERS_H_VERSION "$Id: filters.h,v 1.24 2006/12/29 18:30:46 fabiankeil Exp $" +#define FILTERS_H_VERSION "$Id: filters.h,v 1.25 2007/01/12 15:36:44 fabiankeil Exp $" /********************************************************************* * * File : $Source: /cvsroot/ijbswa/current/filters.h,v $ @@ -39,6 +39,10 @@ * * Revisions : * $Log: filters.h,v $ + * Revision 1.25 2007/01/12 15:36:44 fabiankeil + * Mark *csp as immutable for is_untrusted_url() + * and is_imageurl(). Closes FR 1237736. + * * Revision 1.24 2006/12/29 18:30:46 fabiankeil * Fixed gcc43 conversion warnings, * changed sprintf calls to snprintf. @@ -243,7 +247,7 @@ struct url_spec; */ #ifdef FEATURE_ACL extern int block_acl(struct access_control_addr *dst, struct client_state *csp); -extern int acl_addr(char *aspec, struct access_control_addr *aca); +extern int acl_addr(const char *aspec, struct access_control_addr *aca); #endif /* def FEATURE_ACL */ extern int match_portlist(const char *portlist, int port); -- 2.39.2