Skip to content

Commit

Permalink
Merge pull request wolfSSL#6892 from embhorn/gh6890
Browse files Browse the repository at this point in the history
Add error reporting to loadX509orX509REQFromBuffer
  • Loading branch information
JacobBarthelmeh authored Nov 22, 2023
2 parents 9810a8c + 962e35a commit 2f920b5
Showing 1 changed file with 18 additions and 5 deletions.
23 changes: 18 additions & 5 deletions src/x509.c
Original file line number Diff line number Diff line change
Expand Up @@ -5218,15 +5218,16 @@ static WOLFSSL_X509* loadX509orX509REQFromBuffer(
const unsigned char* buf, int sz, int format, int type)
{

int ret;
int ret = 0;
WOLFSSL_X509* x509 = NULL;
DerBuffer* der = NULL;

WOLFSSL_ENTER("wolfSSL_X509_load_certificate_ex");

if (format == WOLFSSL_FILETYPE_PEM) {
#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);
}
#else
Expand All @@ -5252,20 +5253,28 @@ static WOLFSSL_X509* loadX509orX509REQFromBuffer(
#ifdef WOLFSSL_SMALL_STACK
cert = (DecodedCert*)XMALLOC(sizeof(DecodedCert), NULL,
DYNAMIC_TYPE_DCERT);
if (cert != NULL)
if (cert == NULL) {
ret = MEMORY_ERROR;
}
else
#endif
{
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,
DYNAMIC_TYPE_X509);
if (x509 != NULL) {
InitX509(x509, 1, NULL);
if (CopyDecodedToX509(x509, cert) != 0) {
ret = CopyDecodedToX509(x509, cert);
if (ret != 0) {
wolfSSL_X509_free(x509);
x509 = NULL;
}
}
else {
ret = MEMORY_ERROR;
}
}

FreeDecodedCert(cert);
Expand All @@ -5277,6 +5286,10 @@ static WOLFSSL_X509* loadX509orX509REQFromBuffer(
FreeDer(&der);
}

if (ret != 0) {
WOLFSSL_ERROR(ret);
}

return x509;
}

Expand Down

0 comments on commit 2f920b5

Please sign in to comment.