From: wessels <> Date: Wed, 18 Dec 1996 10:50:23 +0000 (+0000) Subject: make request header parsing more robust X-Git-Tag: SQUID_3_0_PRE1~5273 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ca85027ada07347cfa5e30904409e06f3be90817;p=thirdparty%2Fsquid.git make request header parsing more robust --- diff --git a/src/http.cc b/src/http.cc index 1ee4446755..7b46403c08 100644 --- a/src/http.cc +++ b/src/http.cc @@ -1,5 +1,5 @@ /* - * $Id: http.cc,v 1.139 1996/12/17 07:16:54 wessels Exp $ + * $Id: http.cc,v 1.140 1996/12/18 03:50:23 wessels Exp $ * * DEBUG: section 11 Hypertext Transfer Protocol (HTTP) * AUTHOR: Harvest Derived @@ -296,7 +296,7 @@ void httpParseReplyHeaders(const char *buf, struct _http_reply *reply) { char *headers = get_free_4k_page(); - char *line = get_free_4k_page(); + char *line; char *end; char *s = NULL; char *t; @@ -307,8 +307,18 @@ httpParseReplyHeaders(const char *buf, struct _http_reply *reply) ReplyHeaderStats.parsed++; xstrncpy(headers, buf, 4096); end = mime_headers_end(headers); - if (end) - reply->hdr_sz = end - headers; + if (end == NULL) { + t = headers; + if (!strncasecmp(t, "HTTP/", 5)) { + reply->version = atof(t+5); + if ((t = strchr(t, ' '))) + reply->code = atoi(++t); + } + put_free_4k_page(headers); + return; + } + reply->hdr_sz = end - headers; + line = get_free_4k_page(); for (s = headers; s < end; s += strcspn(s, crlf), s += strspn(s, crlf)) { l = strcspn(s, crlf) + 1; if (l > 4096) @@ -317,7 +327,7 @@ httpParseReplyHeaders(const char *buf, struct _http_reply *reply) t = line; debug(11, 3, "httpParseReplyHeaders: %s\n", t); if (!strncasecmp(t, "HTTP/", 5)) { - sscanf(t + 5, "%lf", &reply->version); + reply->version = atof(t+5); if ((t = strchr(t, ' '))) reply->code = atoi(++t); } else if (!strncasecmp(t, "Content-type:", 13)) { diff --git a/src/mime.cc b/src/mime.cc index e6cd48c309..49f9d8b40b 100644 --- a/src/mime.cc +++ b/src/mime.cc @@ -1,5 +1,5 @@ /* - * $Id: mime.cc,v 1.26 1996/12/05 17:36:12 wessels Exp $ + * $Id: mime.cc,v 1.27 1996/12/18 03:50:24 wessels Exp $ * * DEBUG: section 25 MIME Parsing * AUTHOR: Harvest Derived @@ -159,7 +159,7 @@ mime_headers_end(const char *mime) const char *p1, *p2; const char *end = NULL; - p1 = strstr(mime, "\r\n\r\n"); + p1 = strstr(mime, "\n\r\n"); p2 = strstr(mime, "\n\n"); if (p1 && p2) @@ -167,7 +167,7 @@ mime_headers_end(const char *mime) else end = p1 ? p1 : p2; if (end) - end += (end == p1 ? 4 : 2); + end += (end == p1 ? 3 : 2); return (char *) end; }