Skip to content

Commit f286f62

Browse files
authored
Merge pull request #10201 from gasbytes/quic_record_cap
add missing WOLFSSL_QUIC_MAX_RECORD_CAPACITY check on the early-data
2 parents 6be03a5 + 1576cf9 commit f286f62

2 files changed

Lines changed: 65 additions & 0 deletions

File tree

src/quic.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,11 @@ static QuicRecord *quic_record_make(WOLFSSL *ssl,
7676
qr->level = level;
7777
if (level == wolfssl_encryption_early_data) {
7878
qr->capacity = qr->len = (word32)len;
79+
if (qr->capacity > WOLFSSL_QUIC_MAX_RECORD_CAPACITY) {
80+
WOLFSSL_MSG("QUIC early data length larger than expected");
81+
quic_record_free(ssl, qr);
82+
return NULL;
83+
}
7984
}
8085
else {
8186
qr->capacity = qr->len = (word32) qr_length(data, len);

tests/quic.c

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -390,6 +390,65 @@ static int test_provide_quic_data(void) {
390390
return EXPECT_RESULT();
391391
}
392392

393+
static int test_quic_record_cap(void) {
394+
EXPECT_DECLS;
395+
WOLFSSL_CTX * ctx = NULL;
396+
WOLFSSL * ssl = NULL;
397+
size_t over = (size_t)WOLFSSL_QUIC_MAX_RECORD_CAPACITY + 512U * 1024U;
398+
uint8_t * buf = NULL;
399+
uint8_t hdr[4];
400+
word32 rlen;
401+
402+
ExpectNotNull(buf = (uint8_t*)XMALLOC(over, NULL, DYNAMIC_TYPE_TMP_BUFFER));
403+
if (buf != NULL)
404+
XMEMSET(buf, 0, over);
405+
406+
ExpectNotNull(ctx = wolfSSL_CTX_new(wolfTLSv1_3_client_method()));
407+
ExpectTrue(wolfSSL_CTX_set_quic_method(ctx, &dummy_method) == WOLFSSL_SUCCESS);
408+
409+
/* early_data with over-cap length must be rejected */
410+
ExpectNotNull(ssl = wolfSSL_new(ctx));
411+
ExpectTrue(provide_data(ssl, wolfssl_encryption_early_data, buf, over, 1));
412+
wolfSSL_free(ssl);
413+
ssl = NULL;
414+
415+
/* early_data at exactly cap must succeed */
416+
ExpectNotNull(ssl = wolfSSL_new(ctx));
417+
ExpectTrue(provide_data(ssl, wolfssl_encryption_early_data, buf,
418+
WOLFSSL_QUIC_MAX_RECORD_CAPACITY, 0));
419+
wolfSSL_free(ssl);
420+
ssl = NULL;
421+
422+
/* early_data at cap+1 must be rejected */
423+
ExpectNotNull(ssl = wolfSSL_new(ctx));
424+
ExpectTrue(provide_data(ssl, wolfssl_encryption_early_data, buf,
425+
(size_t)WOLFSSL_QUIC_MAX_RECORD_CAPACITY + 1U, 1));
426+
wolfSSL_free(ssl);
427+
ssl = NULL;
428+
429+
/* early_data well within cap must succeed */
430+
ExpectNotNull(ssl = wolfSSL_new(ctx));
431+
ExpectTrue(provide_data(ssl, wolfssl_encryption_early_data, buf, 1024, 0));
432+
wolfSSL_free(ssl);
433+
ssl = NULL;
434+
435+
/* handshake with over-cap record header must also be rejected */
436+
rlen = (word32)WOLFSSL_QUIC_MAX_RECORD_CAPACITY + 16U - 4U;
437+
hdr[0] = 0x16;
438+
hdr[1] = (byte)(rlen >> 16);
439+
hdr[2] = (byte)(rlen >> 8);
440+
hdr[3] = (byte)rlen;
441+
ExpectNotNull(ssl = wolfSSL_new(ctx));
442+
ExpectTrue(provide_data(ssl, wolfssl_encryption_handshake, hdr, 4, 1));
443+
wolfSSL_free(ssl);
444+
445+
wolfSSL_CTX_free(ctx);
446+
if (buf != NULL)
447+
XFREE(buf, NULL, DYNAMIC_TYPE_TMP_BUFFER);
448+
449+
printf(" test_quic_record_cap: %s\n", (EXPECT_SUCCESS()) ? pass : fail);
450+
return EXPECT_RESULT();
451+
}
393452

394453
static int test_quic_crypt(void) {
395454
EXPECT_DECLS;
@@ -1939,6 +1998,7 @@ int QuicTest(void)
19391998
if ((ret = test_set_quic_method()) != TEST_SUCCESS) goto leave;
19401999
#ifndef NO_WOLFSSL_CLIENT
19412000
if ((ret = test_provide_quic_data()) != TEST_SUCCESS) goto leave;
2001+
if ((ret = test_quic_record_cap()) != TEST_SUCCESS) goto leave;
19422002
if ((ret = test_quic_crypt()) != TEST_SUCCESS) goto leave;
19432003
if ((ret = test_quic_client_hello(verbose)) != TEST_SUCCESS) goto leave;
19442004
#endif

0 commit comments

Comments
 (0)