Squid-2.3.DEVEL2: 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. Sat Sep 4 01:30:26 CEST 1999 Modified Files in squid/src tools.c Bugfix to the escaping control patch. It was completely broken (always true) and didn't look for high control characters (0x7f-0x9f) if it had worked. Index: squid/src/tools.c diff -u squid/src/tools.c:1.1.1.23 squid/src/tools.c:1.1.1.23.2.3 --- squid/src/tools.c:1.1.1.23 Sat Aug 7 17:13:33 1999 +++ squid/src/tools.c Sat Sep 4 01:30:25 1999 @@ -882,4 +882,15 @@ debug(21, errno == ENOENT ? 2 : 1) ("xrename: Cannot rename %s to %s: %s\n", from, to, xstrerror()); return -1; +} + +int +stringHasCntl(const unsigned char *s) +{ + unsigned char c; + while ((c = *s++) != '\0') { + if ( (c & 0x7f) <= 0x1f || c == 0x7f ) + return 1; + } + return 0; } Index: squid/include/util.h diff -u squid/include/util.h:1.1.1.13.24.1 squid/include/util.h:1.1.1.13.24.2 --- squid/include/util.h:1.1.1.13.24.1 Sat Aug 7 22:08:06 1999 +++ squid/include/util.h Sun Aug 8 02:19:52 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.10.2.1 squid/lib/rfc1738.c:1.1.1.10.2.2 --- squid/lib/rfc1738.c:1.1.1.10.2.1 Sat Aug 7 22:08:19 1999 +++ squid/lib/rfc1738.c Sun Aug 8 02:19:55 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.43.2.4 squid/src/client_side.c:1.1.1.43.2.5 --- squid/src/client_side.c:1.1.1.43.2.4 Sat Aug 7 22:11:34 1999 +++ squid/src/client_side.c Sun Aug 8 02:20:04 1999 @@ -2240,10 +2240,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.43.2.3 squid/src/protos.h:1.1.1.43.2.4 --- squid/src/protos.h:1.1.1.43.2.3 Sat Aug 7 19:59:24 1999 +++ squid/src/protos.h Sun Aug 8 02:20:05 1999 @@ -1093,6 +1093,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 *); extern void linklistPush(link_list **, void *); extern void *linklistShift(link_list **); extern int xrename(const char *from, const char *to); Index: squid/src/url.c diff -u squid/src/url.c:1.1.1.27.2.2 squid/src/url.c:1.1.1.27.2.3 --- squid/src/url.c:1.1.1.27.2.2 Sat Aug 7 22:03:05 1999 +++ squid/src/url.c Sun Aug 8 02:20:05 1999 @@ -265,7 +265,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: @@ -358,8 +358,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; }