Squid-2.2.STABLE4: Escape control characters in log files [depends on ftp_password_urls] This patch escapes any control characters in the log files, and also fixes a problem with "uri_whitespace encode" where already escaped characters could get doubly escaped. Index: squid/include/util.h diff -u squid/include/util.h:1.1.1.13.22.1 squid/include/util.h:1.1.1.13.22.2 --- squid/include/util.h:1.1.1.13.22.1 Tue Jul 13 00:46:42 1999 +++ squid/include/util.h Tue Jul 27 20:47:06 1999 @@ -80,6 +80,7 @@ /* rfc1738.c */ extern char *rfc1738_escape(const char *); +extern char *rfc1738_escape_unescaped(const char *); extern char *rfc1738_escape_part(const char *); extern void rfc1738_unescape(char *); Index: squid/lib/rfc1738.c diff -u squid/lib/rfc1738.c:1.1.1.9.2.1 squid/lib/rfc1738.c:1.1.1.9.2.2 --- squid/lib/rfc1738.c:1.1.1.9.2.1 Tue Jul 13 00:46:49 1999 +++ squid/lib/rfc1738.c Tue Jul 27 20:47:20 1999 @@ -54,7 +54,9 @@ (char) 0x3E, /* > */ (char) 0x22, /* " */ (char) 0x23, /* # */ +#if 0 /* done in code */ (char) 0x25, /* % */ +#endif (char) 0x7B, /* { */ (char) 0x7D, /* } */ (char) 0x7C, /* | */ @@ -107,8 +109,11 @@ break; } } + /* Handle % separately */ + if (encode_reserved >= 0 && *p == '%') + do_escape = 1; /* RFC 1738 defines these chars as reserved */ - for (i = 0; i < sizeof(rfc1738_reserved_chars) && encode_reserved ; i++) { + for (i = 0; i < sizeof(rfc1738_reserved_chars) && encode_reserved > 0 ; i++) { if (*p == rfc1738_reserved_chars[i]) { do_escape = 1; break; @@ -150,6 +155,16 @@ rfc1738_escape(const char *url) { return rfc1738_do_escape(url, 0); +} + +/* + * rfc1738_escape_unescaped - Returns a static buffer contains the RFC 1738 + * compliant, escaped version of the given url. + */ +char * +rfc1738_escape_unescaped(const char *url) +{ + return rfc1738_do_escape(url, -1); } /* Index: squid/src/client_side.c diff -u squid/src/client_side.c:1.1.1.42.2.4 squid/src/client_side.c:1.1.1.42.2.5 --- squid/src/client_side.c:1.1.1.42.2.4 Tue Jul 13 01:12:45 1999 +++ squid/src/client_side.c Tue Jul 27 20:47:47 1999 @@ -2118,10 +2118,10 @@ strcpy(http->uri, url); http->flags.accel = 0; } - if (!stringHasWhitespace(http->uri)) + if (!stringHasCntl(http->uri)) http->log_uri = xstrndup(http->uri, MAX_URL); else - http->log_uri = xstrndup(rfc1738_escape(http->uri), MAX_URL); + http->log_uri = xstrndup(rfc1738_escape_unescaped(http->uri), MAX_URL); debug(33, 5) ("parseHttpRequest: Complete request received\n"); if (free_request) safe_free(url); Index: squid/src/protos.h diff -u squid/src/protos.h:1.1.1.42.2.5 squid/src/protos.h:1.1.1.42.2.6 --- squid/src/protos.h:1.1.1.42.2.5 Tue Jul 27 17:48:37 1999 +++ squid/src/protos.h Tue Jul 27 20:47:48 1999 @@ -1041,6 +1041,7 @@ extern const char *gb_to_str(const gb_t *); extern void gb_flush(gb_t *); /* internal, do not use this */ extern int stringHasWhitespace(const char *); +extern int stringHasCntl(const unsigned char *); #if USE_HTCP extern void htcpInit(void); Index: squid/src/tools.c diff -u squid/src/tools.c:1.1.1.22.2.1 squid/src/tools.c:1.1.1.22.2.2 --- squid/src/tools.c:1.1.1.22.2.1 Tue Jul 13 00:34:02 1999 +++ squid/src/tools.c Tue Jul 27 20:47:49 1999 @@ -858,3 +858,14 @@ { return (strcspn(s, w_space) != strlen(s)); } + +int +stringHasCntl(const unsigned char *s) +{ + char c; + while ((c = *s++) != '\0') { + if ( *s <= 0x1f ) + return 1; + } + return 0; +} Index: squid/src/url.c diff -u squid/src/url.c:1.1.1.26.2.1 squid/src/url.c:1.1.1.26.2.2 --- squid/src/url.c:1.1.1.26.2.1 Tue Jul 13 00:45:19 1999 +++ squid/src/url.c Tue Jul 27 20:47:49 1999 @@ -262,7 +262,7 @@ case URI_WHITESPACE_ALLOW: break; case URI_WHITESPACE_ENCODE: - t = rfc1738_escape(urlpath); + t = rfc1738_escape_unescaped(urlpath); xstrncpy(urlpath, t, MAX_URL); break; case URI_WHITESPACE_CHOP: @@ -355,8 +355,8 @@ break; } } - if (stringHasWhitespace(buf)) - xstrncpy(buf, rfc1738_escape(buf), MAX_URL); + if (stringHasCntl(buf)) + xstrncpy(buf, rfc1738_escape_unescaped(buf), MAX_URL); return buf; }