Skip to content

Commit 4764604

Browse files
authored
[+] Fix: Handle illegal STREAM frames in INIT and HSK packets (#524)
1 parent 108a34c commit 4764604

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

src/transport/xqc_frame.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -447,6 +447,16 @@ xqc_process_stream_frame(xqc_connection_t *conn, xqc_packet_in_t *packet_in)
447447
xqc_stream_t *stream = NULL;
448448
xqc_stream_frame_t *stream_frame;
449449

450+
if (packet_in->pi_pkt.pkt_type == XQC_PTYPE_INIT
451+
|| packet_in->pi_pkt.pkt_type == XQC_PTYPE_HSK)
452+
{
453+
xqc_log(conn->log, XQC_LOG_ERROR,
454+
"|illegal STREAM frame in %s packet, close with PROTOCOL_VIOLATION|",
455+
xqc_pkt_type_2_str(packet_in->pi_pkt.pkt_type));
456+
XQC_CONN_ERR(conn, TRA_PROTOCOL_VIOLATION);
457+
return -XQC_EPROTO;
458+
}
459+
450460
stream_frame = xqc_calloc(1, sizeof(xqc_stream_frame_t));
451461
if (stream_frame == NULL) {
452462
xqc_log(conn->log, XQC_LOG_ERROR, "|xqc_calloc error|");

tests/unittest/xqc_process_frame_test.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
char XQC_TEST_ILL_FRAME_1[] = {0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
1414
char XQC_TEST_ZERO_LEN_NEW_TOKEN_FRAME[] = {0x07, 0x00};
15+
char XQC_TEST_STREAM_FRAME[] = {0x0a, 0x00, 0x01, 0x00};
1516

1617

1718
void
@@ -31,6 +32,14 @@ xqc_test_process_frame()
3132
ret = xqc_process_frames(conn, &packet_in);
3233
CU_ASSERT(ret == -XQC_EPROTO);
3334

35+
xqc_packet_in_t pi_stream_init;
36+
memset(&pi_stream_init, 0, sizeof(xqc_packet_in_t));
37+
pi_stream_init.pi_pkt.pkt_type = XQC_PTYPE_INIT;
38+
pi_stream_init.pos = XQC_TEST_STREAM_FRAME;
39+
pi_stream_init.last = pi_stream_init.pos + sizeof(XQC_TEST_STREAM_FRAME);
40+
ret = xqc_process_frames(conn, &pi_stream_init);
41+
CU_ASSERT(ret == -XQC_EPROTO);
42+
3443
xqc_engine_destroy(conn->engine);
3544
}
3645

0 commit comments

Comments
 (0)