Skip to content
7 changes: 6 additions & 1 deletion src/internal.c
Original file line number Diff line number Diff line change
Expand Up @@ -17597,6 +17597,10 @@ static int DoCertificateStatus(WOLFSSL* ssl, byte* input, word32* inOutIdx,
*inOutIdx += status_length;
list_length -= status_length;
}
if (idx >= MAX_CHAIN_DEPTH) {
ret = BUFFER_ERROR;
break;
}
idx++;
}

Expand Down Expand Up @@ -21240,7 +21244,8 @@ static int SanityCheckCipherText(WOLFSSL* ssl, word32 encryptSz)
if (ssl->specs.cipher_type == block) {
#ifdef HAVE_ENCRYPT_THEN_MAC
if (ssl->options.startedETMRead) {
if ((encryptSz - MacSize(ssl)) % ssl->specs.block_size) {
if (encryptSz < minLength ||
(encryptSz - MacSize(ssl)) % ssl->specs.block_size) {
WOLFSSL_MSG("Block ciphertext not block size");
WOLFSSL_ERROR_VERBOSE(SANITY_CIPHER_E);
return SANITY_CIPHER_E;
Expand Down
8 changes: 4 additions & 4 deletions src/ssl.c
Original file line number Diff line number Diff line change
Expand Up @@ -906,6 +906,9 @@ static int DupSSL(WOLFSSL* dup, WOLFSSL* ssl)
XMEMCPY(&dup->version, &ssl->version, sizeof(ProtocolVersion));
XMEMCPY(&dup->chVersion, &ssl->chVersion, sizeof(ProtocolVersion));

/* dup side now owns encrypt/write ciphers */
XMEMSET(&ssl->encrypt, 0, sizeof(Ciphers));

#ifdef HAVE_ONE_TIME_AUTH
#ifdef HAVE_POLY1305
if (ssl->auth.setup && ssl->auth.poly1305 != NULL) {
Expand All @@ -918,9 +921,6 @@ static int DupSSL(WOLFSSL* dup, WOLFSSL* ssl)
#endif
#endif

/* dup side now owns encrypt/write ciphers */
XMEMSET(&ssl->encrypt, 0, sizeof(Ciphers));

#ifdef WOLFSSL_TLS13
if (IsAtLeastTLSv1_3(ssl->version)) {
/* Copy TLS 1.3 application traffic secrets so the write side can
Expand Down Expand Up @@ -1274,7 +1274,7 @@ const char* wolfSSL_get_shared_ciphers(WOLFSSL* ssl, char* buf, int len)
{
const char* cipher;

if (ssl == NULL)
if (ssl == NULL || len <= 0)
return NULL;

cipher = wolfSSL_get_cipher_name_iana(ssl);
Expand Down
22 changes: 18 additions & 4 deletions src/tls13.c
Original file line number Diff line number Diff line change
Expand Up @@ -2966,11 +2966,15 @@ int DecryptTls13(WOLFSSL* ssl, byte* output, const byte* input, word16 sz,
const byte* aad, word16 aadSz)
{
int ret = 0;
word16 dataSz = sz - ssl->specs.aead_mac_size;
word16 dataSz;
word16 macSz = ssl->specs.aead_mac_size;
word32 nonceSz = 0;

WOLFSSL_ENTER("DecryptTls13");
if (sz < ssl->specs.aead_mac_size) {
return BAD_FUNC_ARG;
}
dataSz = sz - ssl->specs.aead_mac_size;

#if defined(WOLFSSL_RENESAS_TSIP_TLS)
ret = tsip_Tls13AesDecrypt(ssl, output, input, sz);
Expand Down Expand Up @@ -5873,7 +5877,7 @@ static int DoTls13CertificateRequest(WOLFSSL* ssl, const byte* input,
* Increase size to handle other implementations sending more than one byte.
* That is, allocate extra space, over one byte, to hold the context value.
*/
certReqCtx = (CertReqCtx*)XMALLOC(sizeof(CertReqCtx) + len - 1, ssl->heap,
certReqCtx = (CertReqCtx*)XMALLOC(sizeof(CertReqCtx) + (len == 0 ? 0 : len - 1), ssl->heap,
DYNAMIC_TYPE_TMP_BUFFER);
if (certReqCtx == NULL)
return MEMORY_E;
Expand Down Expand Up @@ -8766,15 +8770,19 @@ static word32 NextCert(byte* data, word32 length, word32* idx)
{
word32 len;

/* Is index at end of list. */
if (*idx == length)
/* Would index read past end of list? */
if (*idx + 3 > length)
return 0;

/* Length of the current ASN.1 encoded certificate. */
c24to32(data + *idx, &len);
/* Include the length field. */
len += 3;

/* Ensure len does not overrun certificate list */
if (*idx + len > length)
return 0;

/* Move index to next certificate and return the current certificate's
* length.
*/
Expand Down Expand Up @@ -10696,10 +10704,16 @@ static int DoTls13CertificateVerify(WOLFSSL* ssl, byte* input,
* we can decode both lengths here now. */
word32 tmpIdx = args->idx;
word16 tmpSz = 0;
if (args->sz < OPAQUE16_LEN) {
ERROR_OUT(BUFFER_ERROR, exit_dcv);
}
ato16(input + tmpIdx, &tmpSz);
args->sigSz = tmpSz;

tmpIdx += OPAQUE16_LEN + args->sigSz;
if (tmpIdx - args->idx + OPAQUE16_LEN > args->sz) {
ERROR_OUT(BUFFER_ERROR, exit_dcv);
}
ato16(input + tmpIdx, &tmpSz);
args->altSignatureSz = tmpSz;

Expand Down
3 changes: 3 additions & 0 deletions wolfcrypt/src/aes.c
Original file line number Diff line number Diff line change
Expand Up @@ -10360,6 +10360,9 @@ static WARN_UNUSED_RESULT int wc_AesGcmDecrypt_STM32(

ret = wolfSSL_CryptHwMutexLock();
if (ret != 0) {
if (wasAlloc) {
XFREE(authInPadded, aes->heap, DYNAMIC_TYPE_TMP_BUFFER);
}
return ret;
}

Expand Down
13 changes: 11 additions & 2 deletions wolfcrypt/src/asn.c
Original file line number Diff line number Diff line change
Expand Up @@ -9151,8 +9151,13 @@ int wc_CheckPrivateKeyCert(const byte* key, word32 keySz, DecodedCert* der,
if (ret == 0) {
if (der->sapkiOID == RSAk || der->sapkiOID == ECDSAk) {
/* Simply copy the data */
XMEMCPY(decodedPubKey, der->sapkiDer, der->sapkiLen);
pubKeyLen = der->sapkiLen;
if ((word32)der->sapkiLen > pubKeyLen) {
ret = BUFFER_E;
}
else {
XMEMCPY(decodedPubKey, der->sapkiDer, der->sapkiLen);
pubKeyLen = der->sapkiLen;
}
}
else {
#if defined(WC_ENABLE_ASYM_KEY_IMPORT)
Expand Down Expand Up @@ -16211,6 +16216,10 @@ int ConfirmSignature(SignatureCtx* sigCtx,
WOLFSSL_MSG("Verify Signature is too small");
ERROR_OUT(BUFFER_E, exit_cs);
}
else if (sigSz > MAX_ENCODED_SIG_SZ) {
WOLFSSL_MSG("Verify Signature is too big");
ERROR_OUT(BUFFER_E, exit_cs);
}
#ifndef WOLFSSL_NO_MALLOC
sigCtx->key.dsa = (DsaKey*)XMALLOC(sizeof(DsaKey),
sigCtx->heap, DYNAMIC_TYPE_DSA);
Expand Down
Loading