[master] c737577 Straighten out the HPACK error path.

Poul-Henning Kamp phk at FreeBSD.org
Wed Mar 29 20:57:05 CEST 2017


commit c73757749d29af793f470c97d2846629256448a3
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date:   Wed Mar 29 18:55:42 2017 +0000

    Straighten out the HPACK error path.
    
    Fixes #2289

diff --git a/bin/varnishd/http2/cache_http2_hpack.c b/bin/varnishd/http2/cache_http2_hpack.c
index 4b0a1ce..9bcc1dd 100644
--- a/bin/varnishd/http2/cache_http2_hpack.c
+++ b/bin/varnishd/http2/cache_http2_hpack.c
@@ -49,7 +49,7 @@ h2h_checkhdr(const struct http *hp, const char *b, size_t namelen, size_t len)
 
 	if (namelen == 2) {
 		VSLb(hp->vsl, SLT_BogoHeader, "Empty name");
-		return (H2CE_PROTOCOL_ERROR);
+		return (H2SE_PROTOCOL_ERROR);
 	}
 
 	for (p = b; p < b + len; p++) {
@@ -61,7 +61,7 @@ h2h_checkhdr(const struct http *hp, const char *b, size_t namelen, size_t len)
 				VSLb(hp->vsl, SLT_BogoHeader,
 				    "Illegal header name (upper-case): %.*s",
 				    (int)(len > 20 ? 20 : len), b);
-				return (H2CE_PROTOCOL_ERROR);
+				return (H2SE_PROTOCOL_ERROR);
 			}
 			if (vct_istchar(*p)) {
 				/* XXX: vct should have a proper class for
@@ -71,7 +71,7 @@ h2h_checkhdr(const struct http *hp, const char *b, size_t namelen, size_t len)
 			VSLb(hp->vsl, SLT_BogoHeader,
 			    "Illegal header name: %.*s",
 			    (int)(len > 20 ? 20 : len), b);
-			return (H2CE_PROTOCOL_ERROR);
+			return (H2SE_PROTOCOL_ERROR);
 		} else if (p < b + namelen) {
 			/* ': ' added by us */
 			assert(*p == ':' || *p == ' ');
@@ -82,7 +82,7 @@ h2h_checkhdr(const struct http *hp, const char *b, size_t namelen, size_t len)
 			VSLb(hp->vsl, SLT_BogoHeader,
 			    "Illegal header value: %.*s",
 			    (int)(len > 20 ? 20 : len), b);
-			return (H2CE_PROTOCOL_ERROR);
+			return (H2SE_PROTOCOL_ERROR);
 		}
 	}
 
@@ -134,7 +134,7 @@ h2h_addhdr(struct http *hp, char *b, size_t namelen, size_t len)
 			VSLb(hp->vsl, SLT_BogoHeader,
 			    "Unknown pseudo-header: %.*s",
 			    (int)(len > 20 ? 20 : len), b);
-			return (H2SE_PROTOCOL_ERROR);
+			return (H2SE_PROTOCOL_ERROR);	// rfc7540,l,2990,2992
 		}
 	} else
 		n = hp->nhd;
@@ -145,7 +145,7 @@ h2h_addhdr(struct http *hp, char *b, size_t namelen, size_t len)
 			VSLb(hp->vsl, SLT_BogoHeader,
 			    "Duplicate pseudo-header: %.*s",
 			    (int)(len > 20 ? 20 : len), b);
-			return (H2SE_PROTOCOL_ERROR);
+			return (H2SE_PROTOCOL_ERROR);	// rfc7540,l,3158,3162
 		}
 	} else {
 		/* Check for space in struct http */
diff --git a/bin/varnishd/http2/cache_http2_proto.c b/bin/varnishd/http2/cache_http2_proto.c
index 1a85b1e..5e34543 100644
--- a/bin/varnishd/http2/cache_http2_proto.c
+++ b/bin/varnishd/http2/cache_http2_proto.c
@@ -469,7 +469,6 @@ h2_do_req(struct worker *wrk, void *priv)
 	THR_SetRequest(req);
 	req->http->conds = 1;
 	if (CNT_Request(wrk, req) != REQ_FSM_DISEMBARK) {
-		VSL(SLT_Debug, 0, "H2REQ CNT done");
 		AZ(req->ws->r);
 		r2->scheduled = 0;
 		r2->state = H2_S_CLOSED;
@@ -491,7 +490,7 @@ h2_end_headers(struct worker *wrk, const struct h2_sess *h2,
 	FREE_OBJ(r2->decode);
 	r2->state = H2_S_CLOS_REM;
 	if (h2e != NULL) {
-		VSL(SLT_Debug, 0, "H2H_DECODE_FINI %s", h2e->name);
+		VSLb(h2->vsl, SLT_Debug, "HPACK/FINI %s", h2e->name);
 		AZ(r2->req->ws->r);
 		h2_del_req(wrk, r2);
 		return (h2e);
@@ -558,12 +557,12 @@ h2_rx_headers(struct worker *wrk, struct h2_sess *h2, struct h2_req *r2)
 		p += 1;
 	}
 	if (h2->rxf_flags & H2FF_HEADERS_PRIORITY) {
-		p += 5;
 		l -= 5;
+		p += 5;
 	}
 	h2e = h2h_decode_bytes(h2, r2->decode, p, l);
 	if (h2e != NULL) {
-		VSL(SLT_Debug, 0, "H2H_DECODE_BYTES(hdr) %s", h2e->name);
+		VSLb(h2->vsl, SLT_Debug, "HPACK(hdr) %s", h2e->name);
 		(void)h2h_decode_fini(h2, r2->decode);
 		AZ(r2->req->ws->r);
 		h2_del_req(wrk, r2);
@@ -590,7 +589,7 @@ h2_rx_continuation(struct worker *wrk, struct h2_sess *h2, struct h2_req *r2)
 	req = r2->req;
 	h2e = h2h_decode_bytes(h2, r2->decode, h2->rxf_data, h2->rxf_len);
 	if (h2e != NULL) {
-		VSL(SLT_Debug, 0, "H2H_DECODE_BYTES(cont) %s", h2e->name);
+		VSLb(h2->vsl, SLT_Debug, "HPACK(cont) %s", h2e->name);
 		(void)h2h_decode_fini(h2, r2->decode);
 		AZ(r2->req->ws->r);
 		h2_del_req(wrk, r2);
@@ -733,7 +732,6 @@ h2_frame_complete(struct http_conn *htc)
 	if (l < 9)
 		return (HTC_S_MORE);
 	u = vbe32dec(htc->rxbuf_b) >> 8;
-	VSL(SLT_Debug, 0, "RX %p %d %u", htc->rxbuf_b, l, u);
 	if (l < u + 9)	// XXX: Only for !DATA frames
 		return (HTC_S_MORE);
 	return (HTC_S_COMPLETE);
@@ -792,12 +790,11 @@ h2_procframe(struct worker *wrk, struct h2_sess *h2,
 	VSLb(h2->vsl, SLT_Debug, "H2: stream %u: %s", h2->rxf_stream, h2e->txt);
 	vbe32enc(b, h2e->val);
 
-	H2_Send_Get(wrk, h2, r2);
+	H2_Send_Get(wrk, h2, h2->req0);
 	(void)H2_Send_Frame(wrk, h2, H2_F_RST_STREAM,
 	    0, sizeof b, h2->rxf_stream, b);
-	H2_Send_Rel(h2, r2);
+	H2_Send_Rel(h2, h2->req0);
 
-	h2_del_req(wrk, r2);
 	return (0);
 }
 
diff --git a/bin/varnishtest/tests/t02003.vtc b/bin/varnishtest/tests/t02003.vtc
index b2e964f..eef69e2 100644
--- a/bin/varnishtest/tests/t02003.vtc
+++ b/bin/varnishtest/tests/t02003.vtc
@@ -349,6 +349,14 @@ client c1 {
 	} -run
 } -run
 
+client c1 {
+	stream 1 {
+		txreq -hdr ":bla" "foo"
+		rxrst
+		expect rst.err == PROTOCOL_ERROR
+	} -run
+} -run
+
 varnish v1 -vsl_catchup
 
 varnish v1 -expect MEMPOOL.req0.live == 0



More information about the varnish-commit mailing list