Skip to content

Commit 5f44a73

Browse files
Merge pull request #6725 from julek-wolfssl/zd/16598
TLSX_CA_Names_Parse: Include header in length check
2 parents 6b09b5c + 82c5170 commit 5f44a73

2 files changed

Lines changed: 42 additions & 10 deletions

File tree

src/tls.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6677,7 +6677,7 @@ static int TLSX_CA_Names_Parse(WOLFSSL *ssl, const byte* input,
66776677
ato16(input, &extLen);
66786678
idx += OPAQUE16_LEN;
66796679

6680-
if (extLen > length)
6680+
if (idx + extLen > length)
66816681
ret = BUFFER_ERROR;
66826682

66836683
if (ret == 0) {

tests/api.c

Lines changed: 41 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -64288,20 +64288,52 @@ static int test_TLSX_CA_NAMES_bad_extension(void)
6428864288
0x0d, 0x00, 0x00, 0x11, 0x00, 0x00, 0x0d, 0x00, 0x2f, 0x00, 0x01, 0xff,
6428964289
0xff, 0xff, 0xff, 0xfa, 0x0d, 0x00, 0x00, 0x00, 0xad, 0x02
6429064290
};
64291+
const byte shBadCaNamesExt2[] = {
64292+
0x16, 0x03, 0x04, 0x00, 0x3f, 0x02, 0x00, 0x00, 0x3b, 0x03, 0x03, 0xcf,
64293+
0x21, 0xad, 0x74, 0xe5, 0x9a, 0x61, 0x11, 0xbe, 0x1d, 0x8c, 0x02, 0x1e,
64294+
0x65, 0xb8, 0x91, 0xc2, 0xa2, 0x11, 0x16, 0x7a, 0xbb, 0x8c, 0x5e, 0x07,
64295+
0x9e, 0x09, 0xe2, 0xc8, 0xa8, 0x33, 0x9c, 0x00, 0x13, 0x03, 0x00, 0x00,
64296+
0x13, 0x94, 0x7e, 0x00, 0x03, 0x0b, 0xf7, 0x03, 0x00, 0x2b, 0x00, 0x02,
64297+
0x03, 0x04, 0x00, 0x33, 0x00, 0x02, 0x00, 0x19, 0x16, 0x03, 0x03, 0x00,
64298+
0x5e, 0x02, 0x00, 0x00, 0x3b, 0x03, 0x03, 0x7f, 0xd0, 0x2d, 0xea, 0x6e,
64299+
0x53, 0xa1, 0x6a, 0xc9, 0xc8, 0x54, 0xef, 0x75, 0xe4, 0xd9, 0xc6, 0x3e,
64300+
0x74, 0xcb, 0x30, 0x80, 0xcc, 0x83, 0x3a, 0x00, 0x00, 0x00, 0x00, 0x00,
64301+
0x00, 0xc0, 0x5a, 0x00, 0xc0, 0xb5, 0x00, 0x00, 0x11, 0x8f, 0x00, 0x00,
64302+
0x03, 0x03, 0x00, 0x0c, 0x00, 0x2b, 0x00, 0x02, 0x03, 0x04, 0x53, 0x25,
64303+
0x00, 0x00, 0x08, 0x00, 0x00, 0x06, 0x00, 0x04, 0x02, 0x05, 0x00, 0x00,
64304+
0x0d, 0x00, 0x00, 0x11, 0x00, 0x00, 0x0d, 0x00, 0x2f, 0x00, 0x06, 0x00,
64305+
0x04, 0x00, 0x03, 0x30, 0x00, 0x13, 0x94, 0x00, 0x06, 0x00, 0x04, 0x02
64306+
};
64307+
int i = 0;
6429164308

64292-
XMEMSET(&test_ctx, 0, sizeof(test_ctx));
64309+
for (i = 0; i < 2; i++) {
64310+
XMEMSET(&test_ctx, 0, sizeof(test_ctx));
6429364311

64294-
ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, NULL, &ssl_c, NULL,
64295-
wolfTLSv1_3_client_method, NULL), 0);
64312+
ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, NULL, &ssl_c, NULL,
64313+
wolfTLSv1_3_client_method, NULL), 0);
6429664314

64297-
XMEMCPY(test_ctx.c_buff, shBadCaNamesExt, sizeof(shBadCaNamesExt));
64298-
test_ctx.c_len = sizeof(shBadCaNamesExt);
64315+
switch (i) {
64316+
case 0:
64317+
XMEMCPY(test_ctx.c_buff, shBadCaNamesExt,
64318+
sizeof(shBadCaNamesExt));
64319+
test_ctx.c_len = sizeof(shBadCaNamesExt);
64320+
break;
64321+
case 1:
64322+
XMEMCPY(test_ctx.c_buff, shBadCaNamesExt2,
64323+
sizeof(shBadCaNamesExt2));
64324+
test_ctx.c_len = sizeof(shBadCaNamesExt2);
64325+
break;
64326+
}
6429964327

64300-
ExpectIntEQ(wolfSSL_connect(ssl_c), -1);
64301-
ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), BUFFER_ERROR);
64328+
ExpectIntEQ(wolfSSL_connect(ssl_c), -1);
64329+
ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), BUFFER_ERROR);
64330+
64331+
wolfSSL_free(ssl_c);
64332+
ssl_c = NULL;
64333+
wolfSSL_CTX_free(ctx_c);
64334+
ctx_c = NULL;
64335+
}
6430264336

64303-
wolfSSL_free(ssl_c);
64304-
wolfSSL_CTX_free(ctx_c);
6430564337
#endif
6430664338
return EXPECT_RESULT();
6430764339
}

0 commit comments

Comments
 (0)