From 19e30b081f70e5f43e630f11c99fbc3255bf826e Mon Sep 17 00:00:00 2001 From: Uriah Pollock Date: Mon, 24 Oct 2022 16:27:18 -0500 Subject: [PATCH] Resolved sanitizer issue. --- src/crl.c | 12 ++++++++---- src/ocsp.c | 15 +++++++++------ tests/api.c | 2 ++ 3 files changed, 19 insertions(+), 10 deletions(-) diff --git a/src/crl.c b/src/crl.c index e36af26ad..a716e1801 100644 --- a/src/crl.c +++ b/src/crl.c @@ -102,10 +102,12 @@ static int InitCRL_Entry(CRL_Entry* crle, DecodedCRL* dcrl, const byte* buff, #if defined(OPENSSL_EXTRA) crle->lastDateAsn1.length = MAX_DATE_SIZE; - XMEMCPY (crle->lastDateAsn1.data, crle->lastDate, crle->lastDateAsn1.length); + XMEMCPY (crle->lastDateAsn1.data, crle->lastDate, + crle->lastDateAsn1.length); crle->lastDateAsn1.type = crle->lastDateFormat; crle->nextDateAsn1.length = MAX_DATE_SIZE; - XMEMCPY (crle->nextDateAsn1.data, crle->nextDate, crle->nextDateAsn1.length); + XMEMCPY (crle->nextDateAsn1.data, crle->nextDate, + crle->nextDateAsn1.length); crle->nextDateAsn1.type = crle->nextDateFormat; crle->issuer = NULL; @@ -706,10 +708,12 @@ static CRL_Entry* DupCRL_Entry(const CRL_Entry* ent, void* heap) #if defined(OPENSSL_EXTRA) dupl->lastDateAsn1.length = MAX_DATE_SIZE; - XMEMCPY (dupl->lastDateAsn1.data, dupl->lastDate, dupl->lastDateAsn1.length); + XMEMCPY (dupl->lastDateAsn1.data, dupl->lastDate, + dupl->lastDateAsn1.length); dupl->lastDateAsn1.type = dupl->lastDateFormat; dupl->nextDateAsn1.length = MAX_DATE_SIZE; - XMEMCPY (dupl->nextDateAsn1.data, dupl->nextDate, dupl->nextDateAsn1.length); + XMEMCPY (dupl->nextDateAsn1.data, dupl->nextDate, + dupl->nextDateAsn1.length); dupl->nextDateAsn1.type = dupl->nextDateFormat; #endif diff --git a/src/ocsp.c b/src/ocsp.c index c182e0dd8..1141b9e22 100644 --- a/src/ocsp.c +++ b/src/ocsp.c @@ -1074,24 +1074,26 @@ WOLFSSL_OCSP_CERTID* wolfSSL_d2i_OCSP_CERTID(WOLFSSL_OCSP_CERTID** cidOut, { WOLFSSL_OCSP_CERTID *cid = NULL; - if ((cidOut != NULL) && (derIn != NULL) && (length > 0)) { + if ((cidOut != NULL) && (derIn != NULL) && (*derIn != NULL) && + (length > 0)) { cid = *cidOut; /* If a NULL is passed we allocate the memory for the caller. */ - if (cid == NULL) + if (cid == NULL) { cid = (WOLFSSL_OCSP_CERTID*)XMALLOC(sizeof(*cid), NULL, DYNAMIC_TYPE_OPENSSL); - else if (cid->rawCertId) { + } + else if (cid->rawCertId != NULL) { XFREE(cid->rawCertId, NULL, DYNAMIC_TYPE_OPENSSL); cid->rawCertId = NULL; cid->rawCertIdSize = 0; } if (cid != NULL) { - cid->rawCertId = (byte*)XMALLOC(length, NULL, DYNAMIC_TYPE_OPENSSL); + cid->rawCertId = (byte*)XMALLOC(length + 1, NULL, DYNAMIC_TYPE_OPENSSL); if (cid->rawCertId != NULL) { - XMEMCPY (cid->rawCertId, *derIn, length); + XMEMCPY(cid->rawCertId, *derIn, length); cid->rawCertIdSize = length; /* Per spec. advance past the data that is being returned @@ -1104,8 +1106,9 @@ WOLFSSL_OCSP_CERTID* wolfSSL_d2i_OCSP_CERTID(WOLFSSL_OCSP_CERTID** cidOut, } } - if (cid && (!cidOut || cid != *cidOut)) + if (cid && (!cidOut || cid != *cidOut)) { XFREE(cid, NULL, DYNAMIC_TYPE_OPENSSL); + } return NULL; } diff --git a/tests/api.c b/tests/api.c index 4114caaec..709b0fb60 100644 --- a/tests/api.c +++ b/tests/api.c @@ -48158,6 +48158,8 @@ static int test_wolfSSL_d2i_OCSP_CERTID(void) DYNAMIC_TYPE_TMP_BUFFER); XMEMSET(certId, 0, sizeof(*certId)); + /* Reset rawCertIdPtr since it was push forward in the previous call. */ + rawCertIdPtr = &rawCertId[0]; certId = wolfSSL_d2i_OCSP_CERTID(&certId, &rawCertIdPtr, sizeof(rawCertId)); AssertNotNull(certId);