Skip to content

Commit a495bb4

Browse files
committed
TLSX_CA_Names_Parse: make sure to do cleanup when smallstack is on
1 parent 5947c9a commit a495bb4

2 files changed

Lines changed: 17 additions & 11 deletions

File tree

src/tls.c

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6647,6 +6647,7 @@ static int TLSX_CA_Names_Parse(WOLFSSL *ssl, const byte* input,
66476647
word32 idx = 0;
66486648
WOLFSSL_X509_NAME* name = NULL;
66496649
int ret = 0;
6650+
int didInit = FALSE;
66506651
/* Use a DecodedCert struct to get access to GetName to
66516652
* parse DN name */
66526653
#ifdef WOLFSSL_SMALL_STACK
@@ -6664,24 +6665,27 @@ static int TLSX_CA_Names_Parse(WOLFSSL *ssl, const byte* input,
66646665
idx += OPAQUE16_LEN;
66656666

66666667
if (extLen > length)
6667-
return BUFFER_ERROR;
6668-
6669-
InitDecodedCert(cert, input + idx, extLen, ssl->heap);
6670-
idx += extLen;
6668+
ret = BUFFER_ERROR;
66716669

6672-
ret = GetName(cert, SUBJECT, extLen);
6670+
if (ret == 0) {
6671+
InitDecodedCert(cert, input + idx, extLen, ssl->heap);
6672+
didInit = TRUE;
6673+
idx += extLen;
6674+
ret = GetName(cert, SUBJECT, extLen);
6675+
}
66736676

66746677
if (ret == 0 && (name = wolfSSL_X509_NAME_new()) == NULL)
66756678
ret = MEMORY_ERROR;
66766679

6677-
if (ret == 0)
6680+
if (ret == 0) {
66786681
CopyDecodedName(name, cert, SUBJECT);
6679-
6680-
if (ret == 0 && wolfSSL_sk_X509_NAME_push(ssl->client_ca_names, name)
6681-
== WOLFSSL_FAILURE)
6682+
if (wolfSSL_sk_X509_NAME_push(ssl->client_ca_names, name)
6683+
== WOLFSSL_FAILURE)
66826684
ret = MEMORY_ERROR;
6685+
}
66836686

6684-
FreeDecodedCert(cert);
6687+
if (didInit)
6688+
FreeDecodedCert(cert);
66856689

66866690
#ifdef WOLFSSL_SMALL_STACK
66876691
XFREE(cert, ssl->heap, DYNAMIC_TYPE_DCERT);

tests/api.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62947,14 +62947,16 @@ static int test_TLSX_CA_NAMES_bad_extension(void)
6294762947
EXPECT_DECLS;
6294862948
#if defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES) && defined(WOLFSSL_TLS13) && \
6294962949
!defined(NO_CERTS) && !defined(WOLFSSL_NO_CA_NAMES) && \
62950-
defined(OPENSSL_EXTRA)
62950+
defined(OPENSSL_EXTRA) && defined(WOLFSSL_SHA384) && \
62951+
defined(HAVE_NULL_CIPHER)
6295162952
/* This test should only fail (with BUFFER_ERROR) when we actually try to
6295262953
* parse the CA Names extension. Otherwise it will return other non-related
6295362954
* errors. If CA Names will be parsed in more configurations, that should
6295462955
* be reflected in the macro guard above. */
6295562956
WOLFSSL *ssl_c = NULL;
6295662957
WOLFSSL_CTX *ctx_c = NULL;
6295762958
struct test_memio_ctx test_ctx;
62959+
/* HRR + SH using TLS_DHE_PSK_WITH_NULL_SHA384 */
6295862960
const byte shBadCaNamesExt[] = {
6295962961
0x16, 0x03, 0x04, 0x00, 0x3f, 0x02, 0x00, 0x00, 0x3b, 0x03, 0x03, 0xcf,
6296062962
0x21, 0xad, 0x74, 0xe5, 0x9a, 0x61, 0x11, 0xbe, 0x1d, 0x8c, 0x02, 0x1e,

0 commit comments

Comments
 (0)