]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
make request header parsing more robust
authorwessels <>
Wed, 18 Dec 1996 10:50:23 +0000 (10:50 +0000)
committerwessels <>
Wed, 18 Dec 1996 10:50:23 +0000 (10:50 +0000)
src/http.cc
src/mime.cc

index 1ee4446755ec875398bc73842b47cee59ae874ba..7b46403c08a998af4b5b6be34b8e43a80905b724 100644 (file)
@@ -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)) {
index e6cd48c309e5e7c95ac5412f22e1eebbdd1368a0..49f9d8b40b18bc23707fd7eb1b44f140adb5419a 100644 (file)
@@ -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;
 }