Skip to content

Commit 785e633

Browse files
committed
BUG/MEDIUM: h3: Properly limit the number of headers received
The number of headers are limited before the decoding but pseudo headers and cookie headers consume extra slots. In practice, this lowers the maximum number of headers that can be received. To workaround this issue, the limit is doubled during the frame decoding to be sure to have enough extra slots. And the number of headers is tested against the configured limit after the HTX message was created to be able to report an error. Unfortunatly no parsing error are reported because the QUIC multiplexer is not able to do so for now. The same is performed on trailers to be consistent with H2. This patch should be backported as far as 2.6.
1 parent 63d2760 commit 785e633

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

src/h3.c

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -525,7 +525,7 @@ static ssize_t h3_headers_to_htx(struct qcs *qcs, const struct buffer *buf,
525525
struct buffer *tmp = get_trash_chunk();
526526
struct htx *htx = NULL;
527527
struct htx_sl *sl;
528-
struct http_hdr list[global.tune.max_http_hdr];
528+
struct http_hdr list[global.tune.max_http_hdr * 2];
529529
unsigned int flags = HTX_SL_F_NONE;
530530
struct ist meth = IST_NULL, path = IST_NULL;
531531
struct ist scheme = IST_NULL, authority = IST_NULL;
@@ -898,6 +898,12 @@ static ssize_t h3_headers_to_htx(struct qcs *qcs, const struct buffer *buf,
898898
}
899899
}
900900

901+
/* Check the number of blocks agains "tune.http.maxhdr" value before adding EOH block */
902+
if (htx_nbblks(htx) > global.tune.max_http_hdr) {
903+
len = -1;
904+
goto out;
905+
}
906+
901907
if (!htx_add_endof(htx, HTX_BLK_EOH)) {
902908
len = -1;
903909
goto out;
@@ -962,7 +968,7 @@ static ssize_t h3_trailers_to_htx(struct qcs *qcs, const struct buffer *buf,
962968
struct buffer *appbuf = NULL;
963969
struct htx *htx = NULL;
964970
struct htx_sl *sl;
965-
struct http_hdr list[global.tune.max_http_hdr];
971+
struct http_hdr list[global.tune.max_http_hdr * 2];
966972
int hdr_idx, ret;
967973
const char *ctl;
968974
int qpack_err;
@@ -1080,6 +1086,12 @@ static ssize_t h3_trailers_to_htx(struct qcs *qcs, const struct buffer *buf,
10801086
++hdr_idx;
10811087
}
10821088

1089+
/* Check the number of blocks agains "tune.http.maxhdr" value before adding EOT block */
1090+
if (htx_nbblks(htx) > global.tune.max_http_hdr) {
1091+
len = -1;
1092+
goto out;
1093+
}
1094+
10831095
if (!htx_add_endof(htx, HTX_BLK_EOT)) {
10841096
TRACE_ERROR("cannot add trailer", H3_EV_RX_FRAME|H3_EV_RX_HDR, qcs->qcc->conn, qcs);
10851097
len = -1;

0 commit comments

Comments
 (0)