cURL / Mailing Lists / curl-library / Single Mail

curl-library

Crash in curl library while processing HTTP HEAD response

From: isshed <isshed.sip_at_gmail.com>
Date: Thu, 18 Aug 2016 14:43:24 +0530

Hi Experts,

I am new to the curl library. I am facing a crash in the curl library
while processing HTTP HEAD Request. After analyzing the crash dump I
found that HEAD response is coming as "404 - Error: Page Not
Found.\r\n" which is in plain text.

I guess this is the problem. readwrite_http_headers() function could
not parse it and sets the k->header as false and k->badheader as
HEADER_ALLBAD. I could make it work by the followng code changes.

Fix 1:
Index: curl/lib/transfer.c
===================================================================
--- curl/lib/transfer.c (revision 194359)
+++ curl/lib/transfer.c (working copy)
@@ -527,8 +550,18 @@
       Curl_debug(data, CURLINFO_DATA_IN, data->state.headerbuff,
              (size_t)k->hbuflen, conn);
       if(k->badheader == HEADER_PARTHEADER)
- Curl_debug(data, CURLINFO_DATA_IN,
- k->str, (size_t)nread, conn);
+ {
+ Curl_debug(data, CURLINFO_DATA_IN,
+ k->str, (size_t)nread, conn);
+ }
+
+ else if((k->badheader == HEADER_ALLBAD) && data->set.httpreq ==
HTTPREQ_HEAD)
+ {
+ printf("\nreadwrite_data========== If this is head k->chunk
= %d", k->chunk);
+ fflush(stdout);
+ failf(data, "Received problem for head req");
+ return CURLE_HTTP_RETURNED_ERROR;
+ }
     }
     else
       Curl_debug(data, CURLINFO_DATA_IN,

Fix 2:
Index: curl/lib/transfer.c
===================================================================
--- curl/lib/transfer.c (revision 194359)
+++ curl/lib/transfer.c (working copy)
@@ -442,6 +447,14 @@
       /* we are in parse-the-header-mode */
       bool stop_reading = FALSE;
       result = readwrite_http_headers(data, conn, k, &nread, &stop_reading);
+ if((!k->header) && data->set.httpreq == HTTPREQ_HEAD)
+ {
+ printf("\nreadwrite_data========== this is not a head
response no need to process.");
+ fflush(stdout);
+ failf(data, "Received problem for head req");
+ result = CURLE_HTTP_RETURNED_ERROR;
+ }
+
       if(result)
     return result;
       if(stop_reading)

Please let me know which fix I should finalize. Or do you suggest some
new fix. if this has some problem. I am eagerly waiting for your
reply.

Thanks !!!
-------------------------------------------------------------------
List admin: https://cool.haxx.se/list/listinfo/curl-library
Etiquette: https://curl.haxx.se/mail/etiquette.html
Received on 2016-08-18