]> sjero.net Git - wget/commitdiff
[svn] Escape non-printable characters in server response.
authorhniksic <devnull@localhost>
Fri, 2 Feb 2007 09:36:49 +0000 (01:36 -0800)
committerhniksic <devnull@localhost>
Fri, 2 Feb 2007 09:36:49 +0000 (01:36 -0800)
src/ChangeLog
src/http.c

index 0b36ed453acc37862b33f3775a02680c1ffdccda..951af3942e4d351260faae9a0075f0c70dfe4adf 100644 (file)
@@ -1,3 +1,8 @@
+2007-02-02  Hrvoje Niksic  <hniksic@xemacs.org>
+
+       * http.c (print_server_response): Escape non-printable characters
+       in server respone.
+
 2007-02-02  Hrvoje Niksic  <hniksic@xemacs.org>
 
        * netrc.c: Don't make netrc_list static, as it prevents
index ccca44b5321b91ac0617f3758349acf79e8cee16..1ec42d2891e6668c0bd2e73a2a169aa5163e66d8 100644 (file)
@@ -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 "%.<n>s"
-         because resp->headers ends with \0.  */
-      logprintf (LOG_VERBOSE, "%s%.*s\n", prefix, (int) (e - b), b);
+      print_response_line(prefix, b, e);
     }
 }