Blame SOURCES/wget-1.14-CVE-2018-0494.patch

bc22e6
diff --git a/src/http.c b/src/http.c
bc22e6
index b45c404..aa4fd25 100644
bc22e6
--- a/src/http.c
bc22e6
+++ b/src/http.c
bc22e6
@@ -605,9 +605,9 @@ struct response {
bc22e6
    resp_header_*.  */
bc22e6
 
bc22e6
 static struct response *
bc22e6
-resp_new (const char *head)
bc22e6
+resp_new (char *head)
bc22e6
 {
bc22e6
-  const char *hdr;
bc22e6
+  char *hdr;
bc22e6
   int count, size;
bc22e6
 
bc22e6
   struct response *resp = xnew0 (struct response);
bc22e6
@@ -636,15 +636,23 @@ resp_new (const char *head)
bc22e6
         break;
bc22e6
 
bc22e6
       /* Find the end of HDR, including continuations. */
bc22e6
-      do
bc22e6
+      for (;;)
bc22e6
         {
bc22e6
-          const char *end = strchr (hdr, '\n');
bc22e6
+          char *end = strchr (hdr, '\n');
bc22e6
+
bc22e6
           if (end)
bc22e6
             hdr = end + 1;
bc22e6
           else
bc22e6
             hdr += strlen (hdr);
bc22e6
+
bc22e6
+          if (*hdr != ' ' && *hdr != '\t')
bc22e6
+            break;
bc22e6
+
bc22e6
+          // continuation, transform \r and \n into spaces
bc22e6
+          *end = ' ';
bc22e6
+          if (end > head && end[-1] == '\r')
bc22e6
+            end[-1] = ' ';
bc22e6
         }
bc22e6
-      while (*hdr == ' ' || *hdr == '\t');
bc22e6
     }
bc22e6
   DO_REALLOC (resp->headers, size, count + 1, const char *);
bc22e6
   resp->headers[count] = NULL;