@@ -2135,10 +2135,10 @@ static void TLSX_SNI_FreeAll(SNI* list, void* heap)
21352135}
21362136
21372137/** Tells the buffered size of the SNI objects in a list. */
2138- static word16 TLSX_SNI_GetSize(SNI* list)
2138+ WOLFSSL_TEST_VIS word16 TLSX_SNI_GetSize(SNI* list)
21392139{
21402140 SNI* sni;
2141- word16 length = OPAQUE16_LEN; /* list length */
2141+ word32 length = OPAQUE16_LEN; /* list length */
21422142
21432143 while ((sni = list)) {
21442144 list = sni->next;
@@ -2147,12 +2147,16 @@ static word16 TLSX_SNI_GetSize(SNI* list)
21472147
21482148 switch (sni->type) {
21492149 case WOLFSSL_SNI_HOST_NAME:
2150- length += (word16 )XSTRLEN((char*)sni->data.host_name);
2150+ length += (word32 )XSTRLEN((char*)sni->data.host_name);
21512151 break;
21522152 }
2153+
2154+ if (length > WOLFSSL_MAX_16BIT) {
2155+ return 0;
2156+ }
21532157 }
21542158
2155- return length;
2159+ return (word16) length;
21562160}
21572161
21582162/** Writes the SNI objects of a list in a buffer. */
@@ -3216,7 +3220,7 @@ static void TLSX_CSR_Free(CertificateStatusRequest* csr, void* heap)
32163220word16 TLSX_CSR_GetSize_ex(CertificateStatusRequest* csr, byte isRequest,
32173221 int idx)
32183222{
3219- word16 size = 0;
3223+ word32 size = 0;
32203224
32213225 /* shut up compiler warnings */
32223226 (void) csr; (void) isRequest;
@@ -3237,15 +3241,25 @@ word16 TLSX_CSR_GetSize_ex(CertificateStatusRequest* csr, byte isRequest,
32373241 if (csr->ssl != NULL && SSL_CM(csr->ssl) != NULL &&
32383242 SSL_CM(csr->ssl)->ocsp_stapling != NULL &&
32393243 SSL_CM(csr->ssl)->ocsp_stapling->statusCb != NULL) {
3240- return OPAQUE8_LEN + OPAQUE24_LEN + csr->ssl->ocspCsrResp[idx].length;
3244+ if (WOLFSSL_MAX_16BIT - OPAQUE8_LEN - OPAQUE24_LEN <
3245+ csr->ssl->ocspCsrResp[idx].length) {
3246+ return 0;
3247+ }
3248+ size = OPAQUE8_LEN + OPAQUE24_LEN +
3249+ csr->ssl->ocspCsrResp[idx].length;
3250+ return (word16)size;
32413251 }
3242- return (word16)(OPAQUE8_LEN + OPAQUE24_LEN +
3243- csr->responses[idx].length);
3252+ if (WOLFSSL_MAX_16BIT - OPAQUE8_LEN - OPAQUE24_LEN <
3253+ csr->responses[idx].length) {
3254+ return 0;
3255+ }
3256+ size = OPAQUE8_LEN + OPAQUE24_LEN + csr->responses[idx].length;
3257+ return (word16)size;
32443258 }
32453259#else
32463260 (void)idx;
32473261#endif
3248- return size;
3262+ return (word16) size;
32493263}
32503264
32513265#if (defined(WOLFSSL_TLS13) && !defined(NO_WOLFSSL_SERVER))
@@ -3855,7 +3869,7 @@ static void TLSX_CSR2_FreeAll(CertificateStatusRequestItemV2* csr2, void* heap)
38553869static word16 TLSX_CSR2_GetSize(CertificateStatusRequestItemV2* csr2,
38563870 byte isRequest)
38573871{
3858- word16 size = 0;
3872+ word32 size = 0;
38593873
38603874 /* shut up compiler warnings */
38613875 (void) csr2; (void) isRequest;
@@ -3876,11 +3890,15 @@ static word16 TLSX_CSR2_GetSize(CertificateStatusRequestItemV2* csr2,
38763890 size += OCSP_NONCE_EXT_SZ;
38773891 break;
38783892 }
3893+
3894+ if (size > WOLFSSL_MAX_16BIT) {
3895+ return 0;
3896+ }
38793897 }
38803898 }
38813899#endif
38823900
3883- return size;
3901+ return (word16) size;
38843902}
38853903
38863904static int TLSX_CSR2_Write(CertificateStatusRequestItemV2* csr2,
0 commit comments