Skip to content

Commit 63d2760

Browse files
committed
BUG/MEDIUM: mux-h2: Check the number of headers in HEADERS frame after decoding
There is no explicit test on the number of headers when a HEADERS frame is received. It is implicitely limited by the size of the header list. But it is twice the configured limit to be sure to decode the frame. So now, a check is performed after the HTX message was created. This way, we are sure to not exceed the configured limit after the decoding stage. If there are too many headers, a parsing error is reported. Note the same is performed on the trailers. This patch should patially address the issue #2685. It should be backported to all stable versions.
1 parent e415e3c commit 63d2760

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

src/h2.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -494,6 +494,10 @@ int h2_make_htx_request(struct http_hdr *list, struct htx *htx, unsigned int *ms
494494
goto fail;
495495
}
496496

497+
/* Check the number of blocks agains "tune.http.maxhdr" value before adding EOH block */
498+
if (htx_nbblks(htx) > global.tune.max_http_hdr)
499+
goto fail;
500+
497501
/* now send the end of headers marker */
498502
if (!htx_add_endof(htx, HTX_BLK_EOH))
499503
goto fail;
@@ -745,6 +749,10 @@ int h2_make_htx_response(struct http_hdr *list, struct htx *htx, unsigned int *m
745749
*/
746750
}
747751

752+
/* Check the number of blocks agains "tune.http.maxhdr" value before adding EOH block */
753+
if (htx_nbblks(htx) > global.tune.max_http_hdr)
754+
goto fail;
755+
748756
/* now send the end of headers marker */
749757
if (!htx_add_endof(htx, HTX_BLK_EOH))
750758
goto fail;
@@ -812,6 +820,10 @@ int h2_make_htx_trailers(struct http_hdr *list, struct htx *htx)
812820
goto fail;
813821
}
814822

823+
/* Check the number of blocks agains "tune.http.maxhdr" value before adding EOT block */
824+
if (htx_nbblks(htx) > global.tune.max_http_hdr)
825+
goto fail;
826+
815827
if (!htx_add_endof(htx, HTX_BLK_EOT))
816828
goto fail;
817829

src/mux_h2.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5979,6 +5979,7 @@ static int h2c_dec_hdrs(struct h2c *h2c, struct buffer *rxbuf, uint32_t *flags,
59795979
/* Trailers terminate a DATA sequence */
59805980
if (h2_make_htx_trailers(list, htx) <= 0) {
59815981
TRACE_STATE("failed to append HTX trailers into rxbuf", H2_EV_RX_FRAME|H2_EV_RX_HDR|H2_EV_H2S_ERR, h2c->conn);
5982+
htx->flags |= HTX_FL_PARSING_ERROR;
59825983
goto fail;
59835984
}
59845985
*flags |= H2_SF_ES_RCVD;

0 commit comments

Comments
 (0)