From: Amos Jeffries Date: Mon, 29 Mar 2010 22:47:44 +0000 (+1200) Subject: Author: Yannick Bergeron X-Git-Tag: SQUID_3_1_2~29 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=73eec694a7d60176ef10fcbf0e12b7bb4adfd576;p=thirdparty%2Fsquid.git Author: Yannick Bergeron Author: Amos Jeffries AIX build fixes Yannick: C code in strict compilers Amos: rfc1738 buffer overflow prevention --- diff --git a/include/rfc2181.h b/include/rfc2181.h index d5c7e1b6a2..197998b874 100644 --- a/include/rfc2181.h +++ b/include/rfc2181.h @@ -21,7 +21,7 @@ */ #define RFC2181_MAXHOSTNAMELEN 256 -/// Back-port macro for old squid code still using SQUIDHOSTNAMELEN without RFC reference. +/** Back-port macro for old squid code still using SQUIDHOSTNAMELEN without RFC reference. */ #define SQUIDHOSTNAMELEN RFC2181_MAXHOSTNAMELEN #endif /* _SQUID_INCLUDE_RFC1123_H */ diff --git a/lib/getfullhostname.c b/lib/getfullhostname.c index 7b1caa6aa2..b7480b2673 100644 --- a/lib/getfullhostname.c +++ b/lib/getfullhostname.c @@ -62,7 +62,7 @@ #include #endif -#endif // 0 +#endif /* 0 */ #if HAVE_UNISTD_H diff --git a/lib/rfc1738.c b/lib/rfc1738.c index a0edaf7576..6158375686 100644 --- a/lib/rfc1738.c +++ b/lib/rfc1738.c @@ -133,7 +133,7 @@ rfc1738_do_escape(const char *url, int flags) * allocated - KA */ if (do_escape == 1) { - (void) sprintf(q, "%%%02X", (unsigned char) *p); + (void) snprintf(q, (bufsize-(p-buf)), "%%%02X", (unsigned char) *p); q += sizeof(char) * 2; } else { *q = *p; @@ -143,43 +143,10 @@ rfc1738_do_escape(const char *url, int flags) return (buf); } -#if 0 /* legacy API */ /* - * rfc1738_escape - Returns a static buffer that contains the RFC - * 1738 compliant, escaped version of the given url. + * Converts a ascii hex code into a binary character. */ -char * -rfc1738_escape(const char *url) -{ - return rfc1738_do_escape(url, 0); -} - -/* - * rfc1738_escape_unescaped - Returns a static buffer that contains - * the RFC 1738 compliant, escaped version of the given url. - */ -char * -rfc1738_escape_unescaped(const char *url) -{ - return rfc1738_do_escape(url, -1); -} - -/* - * rfc1738_escape_part - Returns a static buffer that contains the - * RFC 1738 compliant, escaped version of the given url segment. - */ -char * -rfc1738_escape_part(const char *url) -{ - return rfc1738_do_escape(url, 1); -} -#endif /* 0 */ - -/* - * rfc1738_unescape() - Converts escaped characters (%xy numbers) in - * given the string. %% is a %. %ab is the 8-bit hexadecimal number "ab" - */ -static inline int +static int fromhex(char ch) { if (ch >= '0' && ch <= '9') @@ -191,6 +158,10 @@ fromhex(char ch) return -1; } +/* + * rfc1738_unescape() - Converts escaped characters (%xy numbers) in + * given the string. %% is a %. %ab is the 8-bit hexadecimal number "ab" + */ void rfc1738_unescape(char *s) {