@@ -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
0 commit comments