Skip to content

Commit 90366b7

Browse files
Merge pull request #10142 from kareem-wolfssl/variousFixes2
Various fixes
2 parents fe8541c + eb8ed9e commit 90366b7

4 files changed

Lines changed: 44 additions & 4 deletions

File tree

src/internal.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25993,6 +25993,10 @@ int SendCertificateStatus(WOLFSSL* ssl)
2599325993

2599425994
if (idx > chain->length)
2599525995
break;
25996+
if ((i + 1) >= (1 + MAX_CHAIN_DEPTH)) {
25997+
ret = MAX_CERT_EXTENSIONS_ERR;
25998+
break;
25999+
}
2599626000
ret = CreateOcspRequest(ssl, request, cert, der.buffer,
2599726001
der.length, &ctxOwnsRequest);
2599826002
if (ret == 0) {
@@ -26021,6 +26025,11 @@ int SendCertificateStatus(WOLFSSL* ssl)
2602126025
else {
2602226026
while (ret == 0 &&
2602326027
NULL != (request = ssl->ctx->chainOcspRequest[i])) {
26028+
if ((i + 1) >= MAX_CERT_EXTENSIONS) {
26029+
ret = MAX_CERT_EXTENSIONS_ERR;
26030+
break;
26031+
}
26032+
2602426033
request->ssl = ssl;
2602526034
ret = CheckOcspRequest(SSL_CM(ssl)->ocsp_stapling,
2602626035
request, &responses[++i], ssl->heap);

src/sniffer.c

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4195,6 +4195,9 @@ static int ProcessClientHello(const byte* input, int* sslBytes,
41954195
{
41964196
word16 listLen = 0, offset = 0;
41974197

4198+
if (extLen < OPAQUE16_LEN)
4199+
return BUFFER_ERROR;
4200+
41984201
ato16(input + offset, &listLen);
41994202
offset += OPAQUE16_LEN;
42004203

@@ -4228,7 +4231,13 @@ static int ProcessClientHello(const byte* input, int* sslBytes,
42284231
#ifdef WOLFSSL_TLS13
42294232
case EXT_KEY_SHARE:
42304233
{
4231-
word16 ksLen = (word16)((input[0] << 8) | input[1]);
4234+
word16 ksLen = 0;
4235+
if (extLen < OPAQUE16_LEN) {
4236+
SetError(BUFFER_ERROR_STR, error, session, FATAL_ERROR_STATE);
4237+
return BUFFER_ERROR;
4238+
}
4239+
4240+
ksLen = (word16)((input[0] << 8) | input[1]);
42324241
if (ksLen + OPAQUE16_LEN > extLen) {
42334242
SetError(CLIENT_HELLO_INPUT_STR, error, session, FATAL_ERROR_STATE);
42344243
return WOLFSSL_FATAL_ERROR;
@@ -4252,6 +4261,11 @@ static int ProcessClientHello(const byte* input, int* sslBytes,
42524261
word32 ticketAge;
42534262
const byte *identity, *binders;
42544263

4264+
if (extLen < OPAQUE16_LEN) {
4265+
SetError(BUFFER_ERROR_STR, error, session, FATAL_ERROR_STATE);
4266+
return BUFFER_ERROR;
4267+
}
4268+
42554269
idsLen = (word16)((input[idx] << 8) | input[idx+1]);
42564270
if ((word32)idsLen + OPAQUE16_LEN + idx > (word32)extLen) {
42574271
SetError(CLIENT_HELLO_INPUT_STR, error, session, FATAL_ERROR_STATE);

src/tls.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2816,6 +2816,9 @@ int TLSX_SNI_GetFromBuffer(const byte* clientHello, word32 helloSz,
28162816
} else {
28172817
word16 listLen;
28182818

2819+
if (extLen < OPAQUE16_LEN)
2820+
return BUFFER_ERROR;
2821+
28192822
ato16(clientHello + offset, &listLen);
28202823
offset += OPAQUE16_LEN;
28212824

@@ -3627,6 +3630,14 @@ int ProcessChainOCSPRequest(WOLFSSL* ssl)
36273630

36283631
if (chain && chain->buffer) {
36293632
while (ret == 0 && pos + OPAQUE24_LEN < chain->length) {
3633+
if (i >= MAX_CERT_EXTENSIONS) {
3634+
WOLFSSL_MSG_EX(
3635+
"OCSP request cert chain exceeds maximum length: "
3636+
"i=%d, MAX_CERT_EXTENSIONS=%d", i, MAX_CERT_EXTENSIONS);
3637+
ret = MAX_CERT_EXTENSIONS_ERR;
3638+
break;
3639+
}
3640+
36303641
c24to32(chain->buffer + pos, &der.length);
36313642
pos += OPAQUE24_LEN;
36323643
der.buffer = chain->buffer + pos;

src/tls13.c

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9072,7 +9072,7 @@ static word32 NextCert(byte* data, word32 length, word32* idx)
90729072
* extIdx The index number of certificate status request data
90739073
* for the certificate.
90749074
* offset index offset
9075-
* returns Total number of bytes written.
9075+
* returns Total number of bytes written on success or negative value on error.
90769076
*/
90779077
static int WriteCSRToBuffer(WOLFSSL* ssl, DerBuffer** certExts,
90789078
word16* extSz, word16 extSz_num)
@@ -9087,6 +9087,9 @@ static int WriteCSRToBuffer(WOLFSSL* ssl, DerBuffer** certExts,
90879087
word32 extIdx;
90889088
DerBuffer* der;
90899089

9090+
if (extSz_num > MAX_CERT_EXTENSIONS)
9091+
return MAX_CERT_EXTENSIONS_ERR;
9092+
90909093
ext = TLSX_Find(ssl->extensions, TLSX_STATUS_REQUEST);
90919094
csr = ext ? (CertificateStatusRequest*)ext->data : NULL;
90929095

@@ -9338,8 +9341,11 @@ static int SendTls13Certificate(WOLFSSL* ssl)
93389341
if (ret != 0)
93399342
return ret;
93409343

9341-
ret = WriteCSRToBuffer(ssl, &ssl->buffers.certExts[0], &extSz[0],
9342-
1 /* +1 for leaf */ + (word16)ssl->buffers.certChainCnt);
9344+
if ((1 + ssl->buffers.certChainCnt) > MAX_CERT_EXTENSIONS)
9345+
ret = MAX_CERT_EXTENSIONS_ERR;
9346+
if (ret == 0)
9347+
ret = WriteCSRToBuffer(ssl, &ssl->buffers.certExts[0], &extSz[0],
9348+
1 /* +1 for leaf */ + (word16)ssl->buffers.certChainCnt);
93439349
if (ret < 0)
93449350
return ret;
93459351
totalextSz += ret;

0 commit comments

Comments
 (0)