forked from wolfSSL/wolfssl
ocsp: fix wolfSSL_d2i_OCSP_CERTID
This commit is contained in:
60
src/ocsp.c
60
src/ocsp.c
@@ -1462,46 +1462,50 @@ WOLFSSL_OCSP_CERTID* wolfSSL_d2i_OCSP_CERTID(WOLFSSL_OCSP_CERTID** cidOut,
|
|||||||
int length)
|
int length)
|
||||||
{
|
{
|
||||||
WOLFSSL_OCSP_CERTID *cid = NULL;
|
WOLFSSL_OCSP_CERTID *cid = NULL;
|
||||||
|
int isAllocated = 0;
|
||||||
|
word32 idx = 0;
|
||||||
|
int ret;
|
||||||
|
|
||||||
if ((cidOut != NULL) && (derIn != NULL) && (*derIn != NULL) &&
|
if (derIn == NULL || *derIn == NULL || length <= 0)
|
||||||
(length > 0)) {
|
return NULL;
|
||||||
|
|
||||||
|
if (cidOut != NULL && *cidOut != NULL) {
|
||||||
cid = *cidOut;
|
cid = *cidOut;
|
||||||
|
FreeOcspEntry(cid, NULL);
|
||||||
/* If a NULL is passed we allocate the memory for the caller. */
|
} else {
|
||||||
if (cid == NULL) {
|
cid = (WOLFSSL_OCSP_CERTID*)XMALLOC(sizeof(WOLFSSL_OCSP_CERTID),
|
||||||
cid = (WOLFSSL_OCSP_CERTID*)XMALLOC(sizeof(*cid), NULL,
|
NULL, DYNAMIC_TYPE_OPENSSL);
|
||||||
DYNAMIC_TYPE_OPENSSL);
|
if (cid == NULL)
|
||||||
}
|
return NULL;
|
||||||
else if (cid->rawCertId != NULL) {
|
isAllocated = 1;
|
||||||
XFREE(cid->rawCertId, NULL, DYNAMIC_TYPE_OPENSSL);
|
|
||||||
cid->rawCertId = NULL;
|
|
||||||
cid->rawCertIdSize = 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (cid != NULL) {
|
XMEMSET(cid, 0, sizeof(WOLFSSL_OCSP_CERTID));
|
||||||
cid->rawCertId = (byte*)XMALLOC((size_t)length + 1, NULL, DYNAMIC_TYPE_OPENSSL);
|
cid->status = XMALLOC(sizeof(CertStatus), NULL, DYNAMIC_TYPE_OCSP_STATUS);
|
||||||
if (cid->rawCertId != NULL) {
|
if (cid->status == NULL) {
|
||||||
XMEMCPY(cid->rawCertId, *derIn, (size_t)length);
|
XFREE(cid, NULL, DYNAMIC_TYPE_OPENSSL);
|
||||||
cid->rawCertIdSize = length;
|
return NULL;
|
||||||
|
|
||||||
/* Per spec. advance past the data that is being returned
|
|
||||||
* to the caller. */
|
|
||||||
*cidOut = cid;
|
|
||||||
*derIn = *derIn + length;
|
|
||||||
|
|
||||||
return cid;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
XMEMSET(cid->status, 0, sizeof(CertStatus));
|
||||||
|
cid->ownStatus = 1;
|
||||||
|
|
||||||
if ((cid != NULL) && ((cidOut == NULL) || (cid != *cidOut))) {
|
ret = OcspDecodeCertID(*derIn, &idx, length, cid);
|
||||||
|
if (ret != 0) {
|
||||||
|
FreeOcspEntry(cid, NULL);
|
||||||
|
if (isAllocated) {
|
||||||
XFREE(cid, NULL, DYNAMIC_TYPE_OPENSSL);
|
XFREE(cid, NULL, DYNAMIC_TYPE_OPENSSL);
|
||||||
}
|
}
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
*derIn += idx;
|
||||||
|
|
||||||
|
if (isAllocated && cidOut != NULL)
|
||||||
|
*cidOut = cid;
|
||||||
|
|
||||||
|
return cid;
|
||||||
|
}
|
||||||
|
|
||||||
const WOLFSSL_OCSP_CERTID* wolfSSL_OCSP_SINGLERESP_get0_id(
|
const WOLFSSL_OCSP_CERTID* wolfSSL_OCSP_SINGLERESP_get0_id(
|
||||||
const WOLFSSL_OCSP_SINGLERESP *single)
|
const WOLFSSL_OCSP_SINGLERESP *single)
|
||||||
{
|
{
|
||||||
|
Reference in New Issue
Block a user