Skip to content

Commit cb3c6fb

Browse files
committed
h2: guard PADDED frames with zero-length payload
Fix OOB read in h2_recv_data() and h2_recv_headers() when PADDED is set but frame length is 0: we now require ≥1 payload byte before reading the Pad Length octet. Sends GOAWAY/PROTOCOL_ERROR instead of touching OOB. Signed-off-by: Joshua Rogers <MegaManSec@users.noreply.github.com>
1 parent dea55b5 commit cb3c6fb

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

src/h2.c

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1188,6 +1188,11 @@ h2_recv_data (connection * const con, const uint8_t * const s, const uint32_t le
11881188
uint32_t alen = len; /* actual data len, minus padding */
11891189
uint32_t pad = 0;
11901190
if (s[4] & H2_FLAG_PADDED) {
1191+
/* need at least 1 payload byte for Pad Length */
1192+
if (len < 1) {
1193+
h2_send_goaway_e(con, H2_E_PROTOCOL_ERROR);
1194+
return 0;
1195+
}
11911196
pad = s[9];
11921197
if (pad >= len) {
11931198
h2_send_goaway_e(con, H2_E_PROTOCOL_ERROR);
@@ -1867,8 +1872,13 @@ h2_recv_headers (connection * const con, uint8_t * const s, uint32_t flen)
18671872
const unsigned char *psrc = s + 9;
18681873
uint32_t alen = flen;
18691874
if (s[4] & H2_FLAG_PADDED) {
1870-
++psrc;
1875+
/* need at least 1 payload byte for Pad Length */
1876+
if (alen < 1) {
1877+
h2_send_goaway_e(con, H2_E_PROTOCOL_ERROR);
1878+
return 0;
1879+
}
18711880
const uint32_t pad = s[9];
1881+
++psrc;
18721882
if (alen < 1 + pad) {
18731883
/* Padding that exceeds the size remaining for the header block
18741884
* fragment MUST be treated as a PROTOCOL_ERROR. */

0 commit comments

Comments
 (0)