Skip to content

Commit 82c5170

Browse files
committed
TLSX_CA_Names_Parse: Include header in length check
1 parent 32a07a7 commit 82c5170

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
@@ -64227,20 +64227,52 @@ static int test_TLSX_CA_NAMES_bad_extension(void)
6422764227
0x0d, 0x00, 0x00, 0x11, 0x00, 0x00, 0x0d, 0x00, 0x2f, 0x00, 0x01, 0xff,
6422864228
0xff, 0xff, 0xff, 0xfa, 0x0d, 0x00, 0x00, 0x00, 0xad, 0x02
6422964229
};
64230+
const byte shBadCaNamesExt2[] = {
64231+
0x16, 0x03, 0x04, 0x00, 0x3f, 0x02, 0x00, 0x00, 0x3b, 0x03, 0x03, 0xcf,
64232+
0x21, 0xad, 0x74, 0xe5, 0x9a, 0x61, 0x11, 0xbe, 0x1d, 0x8c, 0x02, 0x1e,
64233+
0x65, 0xb8, 0x91, 0xc2, 0xa2, 0x11, 0x16, 0x7a, 0xbb, 0x8c, 0x5e, 0x07,
64234+
0x9e, 0x09, 0xe2, 0xc8, 0xa8, 0x33, 0x9c, 0x00, 0x13, 0x03, 0x00, 0x00,
64235+
0x13, 0x94, 0x7e, 0x00, 0x03, 0x0b, 0xf7, 0x03, 0x00, 0x2b, 0x00, 0x02,
64236+
0x03, 0x04, 0x00, 0x33, 0x00, 0x02, 0x00, 0x19, 0x16, 0x03, 0x03, 0x00,
64237+
0x5e, 0x02, 0x00, 0x00, 0x3b, 0x03, 0x03, 0x7f, 0xd0, 0x2d, 0xea, 0x6e,
64238+
0x53, 0xa1, 0x6a, 0xc9, 0xc8, 0x54, 0xef, 0x75, 0xe4, 0xd9, 0xc6, 0x3e,
64239+
0x74, 0xcb, 0x30, 0x80, 0xcc, 0x83, 0x3a, 0x00, 0x00, 0x00, 0x00, 0x00,
64240+
0x00, 0xc0, 0x5a, 0x00, 0xc0, 0xb5, 0x00, 0x00, 0x11, 0x8f, 0x00, 0x00,
64241+
0x03, 0x03, 0x00, 0x0c, 0x00, 0x2b, 0x00, 0x02, 0x03, 0x04, 0x53, 0x25,
64242+
0x00, 0x00, 0x08, 0x00, 0x00, 0x06, 0x00, 0x04, 0x02, 0x05, 0x00, 0x00,
64243+
0x0d, 0x00, 0x00, 0x11, 0x00, 0x00, 0x0d, 0x00, 0x2f, 0x00, 0x06, 0x00,
64244+
0x04, 0x00, 0x03, 0x30, 0x00, 0x13, 0x94, 0x00, 0x06, 0x00, 0x04, 0x02
64245+
};
64246+
int i = 0;
6423064247

64231-
XMEMSET(&test_ctx, 0, sizeof(test_ctx));
64248+
for (i = 0; i < 2; i++) {
64249+
XMEMSET(&test_ctx, 0, sizeof(test_ctx));
6423264250

64233-
ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, NULL, &ssl_c, NULL,
64234-
wolfTLSv1_3_client_method, NULL), 0);
64251+
ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, NULL, &ssl_c, NULL,
64252+
wolfTLSv1_3_client_method, NULL), 0);
6423564253

64236-
XMEMCPY(test_ctx.c_buff, shBadCaNamesExt, sizeof(shBadCaNamesExt));
64237-
test_ctx.c_len = sizeof(shBadCaNamesExt);
64254+
switch (i) {
64255+
case 0:
64256+
XMEMCPY(test_ctx.c_buff, shBadCaNamesExt,
64257+
sizeof(shBadCaNamesExt));
64258+
test_ctx.c_len = sizeof(shBadCaNamesExt);
64259+
break;
64260+
case 1:
64261+
XMEMCPY(test_ctx.c_buff, shBadCaNamesExt2,
64262+
sizeof(shBadCaNamesExt2));
64263+
test_ctx.c_len = sizeof(shBadCaNamesExt2);
64264+
break;
64265+
}
6423864266

64239-
ExpectIntEQ(wolfSSL_connect(ssl_c), -1);
64240-
ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), BUFFER_ERROR);
64267+
ExpectIntEQ(wolfSSL_connect(ssl_c), -1);
64268+
ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), BUFFER_ERROR);
64269+
64270+
wolfSSL_free(ssl_c);
64271+
ssl_c = NULL;
64272+
wolfSSL_CTX_free(ctx_c);
64273+
ctx_c = NULL;
64274+
}
6424164275

64242-
wolfSSL_free(ssl_c);
64243-
wolfSSL_CTX_free(ctx_c);
6424464276
#endif
6424564277
return EXPECT_RESULT();
6424664278
}

0 commit comments

Comments
 (0)