mirror of
https://github.com/wolfSSL/wolfssl.git
synced 2025-08-01 19:54:40 +02:00
Add error reporting to loadX509orX509REQFromBuffer
This commit is contained in:
23
src/x509.c
23
src/x509.c
@@ -5203,7 +5203,7 @@ static WOLFSSL_X509* loadX509orX509REQFromBuffer(
|
|||||||
const unsigned char* buf, int sz, int format, int type)
|
const unsigned char* buf, int sz, int format, int type)
|
||||||
{
|
{
|
||||||
|
|
||||||
int ret;
|
int ret = 0;
|
||||||
WOLFSSL_X509* x509 = NULL;
|
WOLFSSL_X509* x509 = NULL;
|
||||||
DerBuffer* der = NULL;
|
DerBuffer* der = NULL;
|
||||||
|
|
||||||
@@ -5211,7 +5211,8 @@ static WOLFSSL_X509* loadX509orX509REQFromBuffer(
|
|||||||
|
|
||||||
if (format == WOLFSSL_FILETYPE_PEM) {
|
if (format == WOLFSSL_FILETYPE_PEM) {
|
||||||
#ifdef WOLFSSL_PEM_TO_DER
|
#ifdef WOLFSSL_PEM_TO_DER
|
||||||
if (PemToDer(buf, sz, type, &der, NULL, NULL, NULL) != 0) {
|
ret = PemToDer(buf, sz, type, &der, NULL, NULL, NULL);
|
||||||
|
if (ret != 0) {
|
||||||
FreeDer(&der);
|
FreeDer(&der);
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
@@ -5237,20 +5238,28 @@ static WOLFSSL_X509* loadX509orX509REQFromBuffer(
|
|||||||
#ifdef WOLFSSL_SMALL_STACK
|
#ifdef WOLFSSL_SMALL_STACK
|
||||||
cert = (DecodedCert*)XMALLOC(sizeof(DecodedCert), NULL,
|
cert = (DecodedCert*)XMALLOC(sizeof(DecodedCert), NULL,
|
||||||
DYNAMIC_TYPE_DCERT);
|
DYNAMIC_TYPE_DCERT);
|
||||||
if (cert != NULL)
|
if (cert == NULL) {
|
||||||
|
ret = MEMORY_ERROR;
|
||||||
|
}
|
||||||
|
else
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
InitDecodedCert(cert, der->buffer, der->length, NULL);
|
InitDecodedCert(cert, der->buffer, der->length, NULL);
|
||||||
if (ParseCertRelative(cert, type, 0, NULL) == 0) {
|
ret = ParseCertRelative(cert, type, 0, NULL);
|
||||||
|
if (ret == 0) {
|
||||||
x509 = (WOLFSSL_X509*)XMALLOC(sizeof(WOLFSSL_X509), NULL,
|
x509 = (WOLFSSL_X509*)XMALLOC(sizeof(WOLFSSL_X509), NULL,
|
||||||
DYNAMIC_TYPE_X509);
|
DYNAMIC_TYPE_X509);
|
||||||
if (x509 != NULL) {
|
if (x509 != NULL) {
|
||||||
InitX509(x509, 1, NULL);
|
InitX509(x509, 1, NULL);
|
||||||
if (CopyDecodedToX509(x509, cert) != 0) {
|
ret = CopyDecodedToX509(x509, cert);
|
||||||
|
if (ret != 0) {
|
||||||
wolfSSL_X509_free(x509);
|
wolfSSL_X509_free(x509);
|
||||||
x509 = NULL;
|
x509 = NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
ret = MEMORY_ERROR;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
FreeDecodedCert(cert);
|
FreeDecodedCert(cert);
|
||||||
@@ -5262,6 +5271,10 @@ static WOLFSSL_X509* loadX509orX509REQFromBuffer(
|
|||||||
FreeDer(&der);
|
FreeDer(&der);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (ret != 0) {
|
||||||
|
WOLFSSL_ERROR(ret);
|
||||||
|
}
|
||||||
|
|
||||||
return x509;
|
return x509;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user