From: hniksic Date: Fri, 2 Feb 2007 09:36:49 +0000 (-0800) Subject: [svn] Escape non-printable characters in server response. X-Git-Tag: v1.13~602 X-Git-Url: http://sjero.net/git/?a=commitdiff_plain;h=a83387134c2fbbe8fb78f5d612705e3e11c95567;hp=a161efc9ec3aaf5d3787f1c7be0653641f9ea1d0;p=wget [svn] Escape non-printable characters in server response. --- diff --git a/src/ChangeLog b/src/ChangeLog index 0b36ed45..951af394 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,8 @@ +2007-02-02 Hrvoje Niksic + + * http.c (print_server_response): Escape non-printable characters + in server respone. + 2007-02-02 Hrvoje Niksic * netrc.c: Don't make netrc_list static, as it prevents diff --git a/src/http.c b/src/http.c index ccca44b5..1ec42d28 100644 --- a/src/http.c +++ b/src/http.c @@ -738,6 +738,20 @@ resp_free (struct response *resp) xfree (resp); } +/* Print a single line of response, the characters [b, e). We tried + getting away with + logprintf (LOG_VERBOSE, "%s%.*s\n", prefix, (int) (e - b), b); + but that failed to escape the non-printable characters and, in fact, + caused crashes in UTF-8 locales. */ + +static void +print_response_line(const char *prefix, const char *b, const char *e) +{ + char *copy; + BOUNDED_TO_ALLOCA(b, e, copy); + logprintf (LOG_VERBOSE, "%s%s\n", prefix, escnonprint(copy)); +} + /* Print the server response, line by line, omitting the trailing CRLF from individual header lines, and prefixed with PREFIX. */ @@ -756,9 +770,7 @@ print_server_response (const struct response *resp, const char *prefix) --e; if (b < e && e[-1] == '\r') --e; - /* This is safe even on printfs with broken handling of "%.s" - because resp->headers ends with \0. */ - logprintf (LOG_VERBOSE, "%s%.*s\n", prefix, (int) (e - b), b); + print_response_line(prefix, b, e); } }