Skip to content

Commit df05597

Browse files
authored
Merge pull request wolfSSL#10079 from rlm2002/ghi10063
Various GI and ZD fixes
2 parents 9c0a9a6 + 8b2fd34 commit df05597

5 files changed

Lines changed: 42 additions & 11 deletions

File tree

src/internal.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17597,6 +17597,10 @@ static int DoCertificateStatus(WOLFSSL* ssl, byte* input, word32* inOutIdx,
1759717597
*inOutIdx += status_length;
1759817598
list_length -= status_length;
1759917599
}
17600+
if (idx >= MAX_CHAIN_DEPTH) {
17601+
ret = BUFFER_ERROR;
17602+
break;
17603+
}
1760017604
idx++;
1760117605
}
1760217606

@@ -21240,7 +21244,8 @@ static int SanityCheckCipherText(WOLFSSL* ssl, word32 encryptSz)
2124021244
if (ssl->specs.cipher_type == block) {
2124121245
#ifdef HAVE_ENCRYPT_THEN_MAC
2124221246
if (ssl->options.startedETMRead) {
21243-
if ((encryptSz - MacSize(ssl)) % ssl->specs.block_size) {
21247+
if (encryptSz < minLength ||
21248+
(encryptSz - MacSize(ssl)) % ssl->specs.block_size) {
2124421249
WOLFSSL_MSG("Block ciphertext not block size");
2124521250
WOLFSSL_ERROR_VERBOSE(SANITY_CIPHER_E);
2124621251
return SANITY_CIPHER_E;

src/ssl.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -906,6 +906,9 @@ static int DupSSL(WOLFSSL* dup, WOLFSSL* ssl)
906906
XMEMCPY(&dup->version, &ssl->version, sizeof(ProtocolVersion));
907907
XMEMCPY(&dup->chVersion, &ssl->chVersion, sizeof(ProtocolVersion));
908908

909+
/* dup side now owns encrypt/write ciphers */
910+
XMEMSET(&ssl->encrypt, 0, sizeof(Ciphers));
911+
909912
#ifdef HAVE_ONE_TIME_AUTH
910913
#ifdef HAVE_POLY1305
911914
if (ssl->auth.setup && ssl->auth.poly1305 != NULL) {
@@ -918,9 +921,6 @@ static int DupSSL(WOLFSSL* dup, WOLFSSL* ssl)
918921
#endif
919922
#endif
920923

921-
/* dup side now owns encrypt/write ciphers */
922-
XMEMSET(&ssl->encrypt, 0, sizeof(Ciphers));
923-
924924
#ifdef WOLFSSL_TLS13
925925
if (IsAtLeastTLSv1_3(ssl->version)) {
926926
/* Copy TLS 1.3 application traffic secrets so the write side can
@@ -1274,7 +1274,7 @@ const char* wolfSSL_get_shared_ciphers(WOLFSSL* ssl, char* buf, int len)
12741274
{
12751275
const char* cipher;
12761276

1277-
if (ssl == NULL)
1277+
if (ssl == NULL || len <= 0)
12781278
return NULL;
12791279

12801280
cipher = wolfSSL_get_cipher_name_iana(ssl);

src/tls13.c

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2966,11 +2966,15 @@ int DecryptTls13(WOLFSSL* ssl, byte* output, const byte* input, word16 sz,
29662966
const byte* aad, word16 aadSz)
29672967
{
29682968
int ret = 0;
2969-
word16 dataSz = sz - ssl->specs.aead_mac_size;
2969+
word16 dataSz;
29702970
word16 macSz = ssl->specs.aead_mac_size;
29712971
word32 nonceSz = 0;
29722972

29732973
WOLFSSL_ENTER("DecryptTls13");
2974+
if (sz < ssl->specs.aead_mac_size) {
2975+
return BAD_FUNC_ARG;
2976+
}
2977+
dataSz = sz - ssl->specs.aead_mac_size;
29742978

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

8769-
/* Is index at end of list. */
8770-
if (*idx == length)
8773+
/* Would index read past end of list? */
8774+
if (*idx + 3 > length)
87718775
return 0;
87728776

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

8782+
/* Ensure len does not overrun certificate list */
8783+
if (*idx + len > length)
8784+
return 0;
8785+
87788786
/* Move index to next certificate and return the current certificate's
87798787
* length.
87808788
*/
@@ -10696,10 +10704,16 @@ static int DoTls13CertificateVerify(WOLFSSL* ssl, byte* input,
1069610704
* we can decode both lengths here now. */
1069710705
word32 tmpIdx = args->idx;
1069810706
word16 tmpSz = 0;
10707+
if (args->sz < OPAQUE16_LEN) {
10708+
ERROR_OUT(BUFFER_ERROR, exit_dcv);
10709+
}
1069910710
ato16(input + tmpIdx, &tmpSz);
1070010711
args->sigSz = tmpSz;
1070110712

1070210713
tmpIdx += OPAQUE16_LEN + args->sigSz;
10714+
if (tmpIdx - args->idx + OPAQUE16_LEN > args->sz) {
10715+
ERROR_OUT(BUFFER_ERROR, exit_dcv);
10716+
}
1070310717
ato16(input + tmpIdx, &tmpSz);
1070410718
args->altSignatureSz = tmpSz;
1070510719

wolfcrypt/src/aes.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10360,6 +10360,9 @@ static WARN_UNUSED_RESULT int wc_AesGcmDecrypt_STM32(
1036010360

1036110361
ret = wolfSSL_CryptHwMutexLock();
1036210362
if (ret != 0) {
10363+
if (wasAlloc) {
10364+
XFREE(authInPadded, aes->heap, DYNAMIC_TYPE_TMP_BUFFER);
10365+
}
1036310366
return ret;
1036410367
}
1036510368

wolfcrypt/src/asn.c

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9151,8 +9151,13 @@ int wc_CheckPrivateKeyCert(const byte* key, word32 keySz, DecodedCert* der,
91519151
if (ret == 0) {
91529152
if (der->sapkiOID == RSAk || der->sapkiOID == ECDSAk) {
91539153
/* Simply copy the data */
9154-
XMEMCPY(decodedPubKey, der->sapkiDer, der->sapkiLen);
9155-
pubKeyLen = der->sapkiLen;
9154+
if ((word32)der->sapkiLen > pubKeyLen) {
9155+
ret = BUFFER_E;
9156+
}
9157+
else {
9158+
XMEMCPY(decodedPubKey, der->sapkiDer, der->sapkiLen);
9159+
pubKeyLen = der->sapkiLen;
9160+
}
91569161
}
91579162
else {
91589163
#if defined(WC_ENABLE_ASYM_KEY_IMPORT)
@@ -16212,6 +16217,10 @@ int ConfirmSignature(SignatureCtx* sigCtx,
1621216217
WOLFSSL_MSG("Verify Signature is too small");
1621316218
ERROR_OUT(BUFFER_E, exit_cs);
1621416219
}
16220+
else if (sigSz > MAX_ENCODED_SIG_SZ) {
16221+
WOLFSSL_MSG("Verify Signature is too big");
16222+
ERROR_OUT(BUFFER_E, exit_cs);
16223+
}
1621516224
#ifndef WOLFSSL_NO_MALLOC
1621616225
sigCtx->key.dsa = (DsaKey*)XMALLOC(sizeof(DsaKey),
1621716226
sigCtx->heap, DYNAMIC_TYPE_DSA);

0 commit comments

Comments
 (0)