Skip to content

Commit 67d4019

Browse files
authored
Merge pull request #7270 from philljj/zd17560
Fix dataASN null pointer dereference in asn.c.
2 parents d1e62b3 + c24add5 commit 67d4019

2 files changed

Lines changed: 27 additions & 14 deletions

File tree

src/tls.c

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3097,6 +3097,7 @@ static word16 TLSX_CSR_Write(CertificateStatusRequest* csr, byte* output,
30973097

30983098
#ifndef NO_WOLFSSL_CLIENT
30993099
if (isRequest) {
3100+
int ret = 0;
31003101
word16 offset = 0;
31013102
word16 length = 0;
31023103

@@ -3110,12 +3111,16 @@ static word16 TLSX_CSR_Write(CertificateStatusRequest* csr, byte* output,
31103111
offset += OPAQUE16_LEN;
31113112

31123113
/* request extensions */
3113-
if (csr->request.ocsp.nonceSz)
3114-
length = (word16)EncodeOcspRequestExtensions(
3115-
&csr->request.ocsp,
3114+
if (csr->request.ocsp.nonceSz) {
3115+
ret = (int)EncodeOcspRequestExtensions(&csr->request.ocsp,
31163116
output + offset + OPAQUE16_LEN,
31173117
OCSP_NONCE_EXT_SZ);
31183118

3119+
if (ret > 0) {
3120+
length = (word16)ret;
3121+
}
3122+
}
3123+
31193124
c16toa(length, output + offset);
31203125
offset += OPAQUE16_LEN + length;
31213126

@@ -3558,6 +3563,7 @@ static word16 TLSX_CSR2_Write(CertificateStatusRequestItemV2* csr2,
35583563

35593564
#ifndef NO_WOLFSSL_CLIENT
35603565
if (isRequest) {
3566+
int ret = 0;
35613567
word16 offset;
35623568
word16 length;
35633569

@@ -3585,12 +3591,17 @@ static word16 TLSX_CSR2_Write(CertificateStatusRequestItemV2* csr2,
35853591
/* request extensions */
35863592
length = 0;
35873593

3588-
if (csr2->request.ocsp[0].nonceSz)
3589-
length = (word16)EncodeOcspRequestExtensions(
3594+
if (csr2->request.ocsp[0].nonceSz) {
3595+
ret = (int)EncodeOcspRequestExtensions(
35903596
&csr2->request.ocsp[0],
35913597
output + offset + OPAQUE16_LEN,
35923598
OCSP_NONCE_EXT_SZ);
35933599

3600+
if (ret > 0) {
3601+
length = (word16)ret;
3602+
}
3603+
}
3604+
35943605
c16toa(length, output + offset);
35953606
offset += OPAQUE16_LEN + length;
35963607
break;

wolfcrypt/src/asn.c

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -36359,18 +36359,20 @@ word32 EncodeOcspRequestExtensions(OcspRequest* req, byte* output, word32 size)
3635936359
/* Check request has nonce to write in extension. */
3636036360
if (req != NULL && req->nonceSz != 0) {
3636136361
DECL_ASNSETDATA(dataASN, ocspNonceExtASN_Length);
36362-
int sz;
36362+
int sz = 0;
3636336363

3636436364
CALLOC_ASNSETDATA(dataASN, ocspNonceExtASN_Length, ret, req->heap);
3636536365

36366-
/* Set nonce extension OID and nonce. */
36367-
SetASN_Buffer(&dataASN[OCSPNONCEEXTASN_IDX_EXT_OID], NonceObjId,
36368-
sizeof(NonceObjId));
36369-
SetASN_Buffer(&dataASN[OCSPNONCEEXTASN_IDX_EXT_NONCE], req->nonce,
36370-
(word32)req->nonceSz);
36371-
/* Calculate size of nonce extension. */
36372-
ret = SizeASN_Items(ocspNonceExtASN, dataASN, ocspNonceExtASN_Length,
36373-
&sz);
36366+
if ((ret == 0) && (output != NULL)) {
36367+
/* Set nonce extension OID and nonce. */
36368+
SetASN_Buffer(&dataASN[OCSPNONCEEXTASN_IDX_EXT_OID], NonceObjId,
36369+
sizeof(NonceObjId));
36370+
SetASN_Buffer(&dataASN[OCSPNONCEEXTASN_IDX_EXT_NONCE], req->nonce,
36371+
(word32)req->nonceSz);
36372+
/* Calculate size of nonce extension. */
36373+
ret = SizeASN_Items(ocspNonceExtASN, dataASN,
36374+
ocspNonceExtASN_Length, &sz);
36375+
}
3637436376
/* Check buffer big enough for encoding if supplied. */
3637536377
if ((ret == 0) && (output != NULL) && (sz > (int)size)) {
3637636378
ret = BUFFER_E;

0 commit comments

Comments
 (0)