Skip to content

Commit 5947c9a

Browse files
committed
TLSX_CA_Names_Parse: Verify the length of the extension
1 parent d87bb14 commit 5947c9a

2 files changed

Lines changed: 53 additions & 0 deletions

File tree

src/tls.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6634,6 +6634,9 @@ static int TLSX_CA_Names_Parse(WOLFSSL *ssl, const byte* input,
66346634
if (ssl->client_ca_names == NULL)
66356635
return MEMORY_ERROR;
66366636

6637+
if (length < OPAQUE16_LEN)
6638+
return BUFFER_ERROR;
6639+
66376640
ato16(input, &extLen);
66386641
input += OPAQUE16_LEN;
66396642
length -= OPAQUE16_LEN;
@@ -6655,6 +6658,8 @@ static int TLSX_CA_Names_Parse(WOLFSSL *ssl, const byte* input,
66556658
DecodedCert cert[1];
66566659
#endif
66576660

6661+
if (length < OPAQUE16_LEN)
6662+
return BUFFER_ERROR;
66586663
ato16(input, &extLen);
66596664
idx += OPAQUE16_LEN;
66606665

tests/api.c

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62942,6 +62942,53 @@ static int test_dtls_no_extensions(void)
6294262942
return EXPECT_RESULT();
6294362943
}
6294462944

62945+
static int test_TLSX_CA_NAMES_bad_extension(void)
62946+
{
62947+
EXPECT_DECLS;
62948+
#if defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES) && defined(WOLFSSL_TLS13) && \
62949+
!defined(NO_CERTS) && !defined(WOLFSSL_NO_CA_NAMES) && \
62950+
defined(OPENSSL_EXTRA)
62951+
/* This test should only fail (with BUFFER_ERROR) when we actually try to
62952+
* parse the CA Names extension. Otherwise it will return other non-related
62953+
* errors. If CA Names will be parsed in more configurations, that should
62954+
* be reflected in the macro guard above. */
62955+
WOLFSSL *ssl_c = NULL;
62956+
WOLFSSL_CTX *ctx_c = NULL;
62957+
struct test_memio_ctx test_ctx;
62958+
const byte shBadCaNamesExt[] = {
62959+
0x16, 0x03, 0x04, 0x00, 0x3f, 0x02, 0x00, 0x00, 0x3b, 0x03, 0x03, 0xcf,
62960+
0x21, 0xad, 0x74, 0xe5, 0x9a, 0x61, 0x11, 0xbe, 0x1d, 0x8c, 0x02, 0x1e,
62961+
0x65, 0xb8, 0x91, 0xc2, 0xa2, 0x11, 0x16, 0x7a, 0xbb, 0x8c, 0x5e, 0x07,
62962+
0x9e, 0x09, 0xe2, 0xc8, 0xa8, 0x33, 0x9c, 0x00, 0x13, 0x03, 0x00, 0x00,
62963+
0x13, 0x94, 0x7e, 0x00, 0x03, 0x0b, 0xf7, 0x03, 0x00, 0x2b, 0x00, 0x02,
62964+
0x03, 0x04, 0x00, 0x33, 0x00, 0x02, 0x00, 0x19, 0x16, 0x03, 0x03, 0x00,
62965+
0x5c, 0x02, 0x00, 0x00, 0x3b, 0x03, 0x03, 0x03, 0xcf, 0x21, 0xad, 0x74,
62966+
0x00, 0x00, 0x83, 0x3f, 0x3b, 0x80, 0x01, 0xac, 0x65, 0x8c, 0x19, 0x2a,
62967+
0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x02, 0x00, 0x9e, 0x09, 0x1c, 0xe8,
62968+
0xa8, 0x09, 0x9c, 0x00, 0xc0, 0xb5, 0x00, 0x00, 0x11, 0x8f, 0x00, 0x00,
62969+
0x03, 0x3f, 0x00, 0x0c, 0x00, 0x2b, 0x00, 0x02, 0x03, 0x04, 0x13, 0x05,
62970+
0x00, 0x00, 0x08, 0x00, 0x00, 0x06, 0x00, 0x04, 0x00, 0x09, 0x00, 0x00,
62971+
0x0d, 0x00, 0x00, 0x11, 0x00, 0x00, 0x0d, 0x00, 0x2f, 0x00, 0x01, 0xff,
62972+
0xff, 0xff, 0xff, 0xfa, 0x0d, 0x00, 0x00, 0x00, 0xad, 0x02
62973+
};
62974+
62975+
XMEMSET(&test_ctx, 0, sizeof(test_ctx));
62976+
62977+
ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, NULL, &ssl_c, NULL,
62978+
wolfTLSv1_3_client_method, NULL), 0);
62979+
62980+
XMEMCPY(test_ctx.c_buff, shBadCaNamesExt, sizeof(shBadCaNamesExt));
62981+
test_ctx.c_len = sizeof(shBadCaNamesExt);
62982+
62983+
ExpectIntEQ(wolfSSL_connect(ssl_c), -1);
62984+
ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), BUFFER_ERROR);
62985+
62986+
wolfSSL_free(ssl_c);
62987+
wolfSSL_CTX_free(ctx_c);
62988+
#endif
62989+
return EXPECT_RESULT();
62990+
}
62991+
6294562992
/*----------------------------------------------------------------------------*
6294662993
| Main
6294762994
*----------------------------------------------------------------------------*/
@@ -64192,6 +64239,7 @@ TEST_CASE testCases[] = {
6419264239
TEST_DECL(test_dtls_ipv6_check),
6419364240
TEST_DECL(test_wolfSSL_SCR_after_resumption),
6419464241
TEST_DECL(test_dtls_no_extensions),
64242+
TEST_DECL(test_TLSX_CA_NAMES_bad_extension),
6419564243
/* This test needs to stay at the end to clean up any caches allocated. */
6419664244
TEST_DECL(test_wolfSSL_Cleanup)
6419764245
};

0 commit comments

Comments
 (0)