r357 - trunk/varnish-cache/bin/varnishd

phk at projects.linpro.no phk at projects.linpro.no
Thu Jul 6 23:00:38 CEST 2006


Author: phk
Date: 2006-07-06 23:00:38 +0200 (Thu, 06 Jul 2006)
New Revision: 357

Modified:
   trunk/varnish-cache/bin/varnishd/cache_http.c
Log:
Strengthen HTTP parsing


Modified: trunk/varnish-cache/bin/varnishd/cache_http.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_http.c	2006-07-06 20:29:26 UTC (rev 356)
+++ trunk/varnish-cache/bin/varnishd/cache_http.c	2006-07-06 21:00:38 UTC (rev 357)
@@ -210,9 +210,11 @@
 {
 	char *p, *q, *r;
 
-	for (p = hp->s ; p < hp->v && isspace(*p); p++)
+	assert(hp->t != NULL);
+	assert(hp->s < hp->t);
+	assert(hp->t <= hp->v);
+	for (p = hp->s ; isspace(*p); p++)
 		continue;
-	assert(hp->t != NULL);
 	if (rr == 1) {
 		/* First, isolate and possibly identify request type */
 		hp->req = p;
@@ -228,22 +230,25 @@
 		while (!isspace(*p))
 			p++;
 		VSLR(SLT_URL, fd, hp->url, p);
-		*p++ = '\0';
+		if (*p != '\n') {
+			*p++ = '\0';
 
-		/* Finally, look for protocol, if any */
-		while (isspace(*p) && *p != '\n')
-			p++;
-		hp->proto = p;
-		if (*p != '\n') {
-			while (!isspace(*p))
+			/* Finally, look for protocol, if any */
+			while (isspace(*p) && *p != '\n')
 				p++;
+			if (*p != '\n') {
+				hp->proto = p;
+				while (!isspace(*p))
+					p++;
+				if (*p != '\n')
+					*p++ = '\0';
+				while (isspace(*p) && *p != '\n')
+					p++;
+			}
 		}
-		VSLR(SLT_Protocol, fd, hp->proto, p);
 		*p++ = '\0';
-
-		while (isspace(*p) && *p != '\n')
-			p++;
-		p++;
+		if (hp->proto != NULL)
+			VSLR(SLT_Protocol, fd, hp->proto, p);
 	} else {
 		/* First, protocol */
 		hp->proto = p;
@@ -369,6 +374,7 @@
 	if (!http_header_complete(hp))
 		return;
 
+	assert(hp->t != NULL);
 	event_del(&hp->ev);
 	if (hp->callback != NULL)
 		hp->callback(hp->arg, 1);
@@ -391,6 +397,7 @@
 		hp->v = hp->s + l;
 		hp->t = hp->s;
 		if (http_header_complete(hp)) {
+			assert(func != NULL);
 			func(arg, 1);
 			return;
 		}
@@ -453,15 +460,21 @@
 		sbuf_cat(sb, hp->req);
 		sbuf_cat(sb, " ");
 		sbuf_cat(sb, hp->url);
-		sbuf_cat(sb, " ");
-		sbuf_cat(sb, hp->proto);
+		if (hp->proto != NULL) {
+			sbuf_cat(sb, " ");
+			sbuf_cat(sb, hp->proto);
+		}
 		sup = 2;
 		break;
 	case Build_Fetch:
 		sbuf_cat(sb, "GET ");
 		sbuf_cat(sb, hp->url);
-		sbuf_cat(sb, " ");
-		sbuf_cat(sb, hp->proto);
+		if (hp->proto != NULL) {
+			sbuf_cat(sb, " ");
+			sbuf_cat(sb, hp->proto);
+		} else {
+			sbuf_cat(sb, " HTTP/1.1");
+		}
 		sup = 1;
 		break;
 	default:




More information about the varnish-commit mailing list