[6.0] b4a5f99d0 http2_hpack: New custom h2 error for http_req_size

Dridi Boukelmoune dridi.boukelmoune at gmail.com
Thu Apr 4 14:33:11 UTC 2024


commit b4a5f99d03520467898619d67f61fd571916c059
Author: Dridi Boukelmoune <dridi.boukelmoune at gmail.com>
Date:   Thu Mar 28 16:02:53 2024 +0100

    http2_hpack: New custom h2 error for http_req_size

diff --git a/bin/varnishd/http2/cache_http2_hpack.c b/bin/varnishd/http2/cache_http2_hpack.c
index 22eaa61f1..25fc0be7d 100644
--- a/bin/varnishd/http2/cache_http2_hpack.c
+++ b/bin/varnishd/http2/cache_http2_hpack.c
@@ -338,7 +338,8 @@ h2h_decode_bytes(struct h2_sess *h2, const uint8_t *in, size_t in_l)
 	/* Only H2E_ENHANCE_YOUR_CALM indicates that we should continue
 	   processing. Other errors should have been returned and handled
 	   by the caller. */
-	assert(d->error == 0 || d->error == H2SE_ENHANCE_YOUR_CALM);
+	if (d->error != NULL)
+		assert(H2_ERROR_MATCH(d->error, H2SE_ENHANCE_YOUR_CALM));
 
 	while (1) {
 		AN(d->out);
@@ -357,7 +358,7 @@ h2h_decode_bytes(struct h2_sess *h2, const uint8_t *in, size_t in_l)
 			break;
 		}
 
-		if (d->error == H2SE_ENHANCE_YOUR_CALM) {
+		if (H2_ERROR_MATCH(d->error, H2SE_ENHANCE_YOUR_CALM)) {
 			d->out_u = 0;
 			assert(d->out_u < d->out_l);
 			continue;
@@ -369,7 +370,7 @@ h2h_decode_bytes(struct h2_sess *h2, const uint8_t *in, size_t in_l)
 		case VHD_NAME:
 			assert(d->namelen == 0);
 			if (d->out_l - d->out_u < 2) {
-				d->error = H2SE_ENHANCE_YOUR_CALM;
+				d->error = H2SE_REQ_SIZE;
 				break;
 			}
 			d->out[d->out_u++] = ':';
@@ -382,7 +383,7 @@ h2h_decode_bytes(struct h2_sess *h2, const uint8_t *in, size_t in_l)
 		case VHD_VALUE:
 			assert(d->namelen > 0);
 			if (d->out_l - d->out_u < 1) {
-				d->error = H2SE_ENHANCE_YOUR_CALM;
+				d->error = H2SE_REQ_SIZE;
 				break;
 			}
 			d->error = h2h_addhdr(hp, d);
@@ -396,7 +397,7 @@ h2h_decode_bytes(struct h2_sess *h2, const uint8_t *in, size_t in_l)
 			break;
 
 		case VHD_BUF:
-			d->error = H2SE_ENHANCE_YOUR_CALM;
+			d->error = H2SE_REQ_SIZE;
 			break;
 
 		default:
@@ -404,7 +405,7 @@ h2h_decode_bytes(struct h2_sess *h2, const uint8_t *in, size_t in_l)
 			break;
 		}
 
-		if (d->error == H2SE_ENHANCE_YOUR_CALM) {
+		if (H2_ERROR_MATCH(d->error, H2SE_ENHANCE_YOUR_CALM)) {
 			d->out = d->reset;
 			d->out_l = hp->ws->r - d->out;
 			d->out_u = 0;
@@ -413,7 +414,7 @@ h2h_decode_bytes(struct h2_sess *h2, const uint8_t *in, size_t in_l)
 			break;
 	}
 
-	if (d->error == H2SE_ENHANCE_YOUR_CALM)
+	if (H2_ERROR_MATCH(d->error, H2SE_ENHANCE_YOUR_CALM))
 		return (0); /* Stream error, delay reporting until
 			       h2h_decode_fini so that we can process the
 			       complete header block */
diff --git a/include/tbl/h2_error.h b/include/tbl/h2_error.h
index 49436f861..2f1303e91 100644
--- a/include/tbl/h2_error.h
+++ b/include/tbl/h2_error.h
@@ -195,6 +195,15 @@ H2_ERROR(
 	/* reason */	SC_BANKRUPT,
 	/* descr */	"http/2 bankrupt connection"
 )
+
+H2_ERROR(
+	/* name */	REQ_SIZE,
+	/* val */	11, /* ENHANCE_YOUR_CALM */
+	/* types */	2,
+	/* goaway */	0,
+	/* reason */	SC_NULL,
+	/* descr */	"HTTP/2 header list exceeded http_req_size"
+)
 #  undef H2_CUSTOM_ERRORS
 #endif
 


More information about the varnish-commit mailing list