From 0e8a66afe678ff84854276f7720a27560ec0bb14 Mon Sep 17 00:00:00 2001
From: Miquel Llobet <mllobet.cm@gmail.com>
Date: Fri, 17 Apr 2015 12:44:31 +0200
Subject: [PATCH] [Patch] Fixed #39175 Header value length limit

src/http.c (gethttp): hdrval now dinamically allocated to 8Kb, changed
all instances of resp_header_copy to resp_header_strdup
---
 src/http.c | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/src/http.c b/src/http.c
index 9911758..5bb3ba4 100644
--- a/src/http.c
+++ b/src/http.c
@@ -2036,8 +2036,7 @@ check_file_output (struct url *u, struct http_stat *hs,
 
       /* Honor Content-Disposition whether possible. */
       if (!opt.content_disposition
-          || !resp_header_copy (resp, "Content-Disposition",
-                                hdrval, hdrsize)
+          || !(hdrval = resp_header_strdup (resp, "Content-Disposition"))
           || !parse_content_disposition (hdrval, &local_file))
         {
           /* The Content-Disposition header is missing or broken.
@@ -2423,7 +2422,7 @@ gethttp (struct url *u, struct http_stat *hs, int *dt, struct url *proxy,
 
   char *head = NULL;
   struct response *resp = NULL;
-  char hdrval[512];
+  char *hdrval = xmalloc(8192);
   char *message = NULL;
 
   /* Declare WARC variables. */
@@ -2697,7 +2696,7 @@ gethttp (struct url *u, struct http_stat *hs, int *dt, struct url *proxy,
     }
 
   if (!opt.ignore_length
-      && resp_header_copy (resp, "Content-Length", hdrval, sizeof (hdrval)))
+      && (hdrval = resp_header_strdup (resp, "Content-Length")))
     {
       wgint parsed;
       errno = 0;
@@ -2724,7 +2723,7 @@ gethttp (struct url *u, struct http_stat *hs, int *dt, struct url *proxy,
   /* Check for keep-alive related responses. */
   if (!inhibit_keep_alive)
     {
-      if (resp_header_copy (resp, "Connection", hdrval, sizeof (hdrval)))
+      if ((hdrval = resp_header_strdup (resp, "Connection")))
         {
           if (0 == c_strcasecmp (hdrval, "Close"))
             keep_alive = false;
@@ -2732,7 +2731,7 @@ gethttp (struct url *u, struct http_stat *hs, int *dt, struct url *proxy,
     }
 
   chunked_transfer_encoding = false;
-  if (resp_header_copy (resp, "Transfer-Encoding", hdrval, sizeof (hdrval))
+  if ((hdrval = resp_header_strdup (resp, "Transfer-Encoding"))
       && 0 == c_strcasecmp (hdrval, "chunked"))
     chunked_transfer_encoding = true;
 
@@ -2882,7 +2881,7 @@ gethttp (struct url *u, struct http_stat *hs, int *dt, struct url *proxy,
   hs->newloc = resp_header_strdup (resp, "Location");
   hs->remote_time = resp_header_strdup (resp, "Last-Modified");
 
-  if (resp_header_copy (resp, "Content-Range", hdrval, sizeof (hdrval)))
+  if ((hdrval = resp_header_strdup (resp, "Content-Range")))
     {
       wgint first_byte_pos, last_byte_pos, entity_length;
       if (parse_content_range (hdrval, &first_byte_pos, &last_byte_pos,
@@ -3170,6 +3169,7 @@ gethttp (struct url *u, struct http_stat *hs, int *dt, struct url *proxy,
   xfree (head);
   xfree (type);
   xfree (message);
+  xfree (hdrval);
   resp_free (&resp);
   request_free (&req);
 
-- 
2.3.0

