Skip to content

Commit 962e35a

Browse files
committed
Add error reporting to loadX509orX509REQFromBuffer
1 parent bab01ca commit 962e35a

1 file changed

Lines changed: 18 additions & 5 deletions

File tree

src/x509.c

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5203,15 +5203,16 @@ static WOLFSSL_X509* loadX509orX509REQFromBuffer(
52035203
const unsigned char* buf, int sz, int format, int type)
52045204
{
52055205

5206-
int ret;
5206+
int ret = 0;
52075207
WOLFSSL_X509* x509 = NULL;
52085208
DerBuffer* der = NULL;
52095209

52105210
WOLFSSL_ENTER("wolfSSL_X509_load_certificate_ex");
52115211

52125212
if (format == WOLFSSL_FILETYPE_PEM) {
52135213
#ifdef WOLFSSL_PEM_TO_DER
5214-
if (PemToDer(buf, sz, type, &der, NULL, NULL, NULL) != 0) {
5214+
ret = PemToDer(buf, sz, type, &der, NULL, NULL, NULL);
5215+
if (ret != 0) {
52155216
FreeDer(&der);
52165217
}
52175218
#else
@@ -5237,20 +5238,28 @@ static WOLFSSL_X509* loadX509orX509REQFromBuffer(
52375238
#ifdef WOLFSSL_SMALL_STACK
52385239
cert = (DecodedCert*)XMALLOC(sizeof(DecodedCert), NULL,
52395240
DYNAMIC_TYPE_DCERT);
5240-
if (cert != NULL)
5241+
if (cert == NULL) {
5242+
ret = MEMORY_ERROR;
5243+
}
5244+
else
52415245
#endif
52425246
{
52435247
InitDecodedCert(cert, der->buffer, der->length, NULL);
5244-
if (ParseCertRelative(cert, type, 0, NULL) == 0) {
5248+
ret = ParseCertRelative(cert, type, 0, NULL);
5249+
if (ret == 0) {
52455250
x509 = (WOLFSSL_X509*)XMALLOC(sizeof(WOLFSSL_X509), NULL,
52465251
DYNAMIC_TYPE_X509);
52475252
if (x509 != NULL) {
52485253
InitX509(x509, 1, NULL);
5249-
if (CopyDecodedToX509(x509, cert) != 0) {
5254+
ret = CopyDecodedToX509(x509, cert);
5255+
if (ret != 0) {
52505256
wolfSSL_X509_free(x509);
52515257
x509 = NULL;
52525258
}
52535259
}
5260+
else {
5261+
ret = MEMORY_ERROR;
5262+
}
52545263
}
52555264

52565265
FreeDecodedCert(cert);
@@ -5262,6 +5271,10 @@ static WOLFSSL_X509* loadX509orX509REQFromBuffer(
52625271
FreeDer(&der);
52635272
}
52645273

5274+
if (ret != 0) {
5275+
WOLFSSL_ERROR(ret);
5276+
}
5277+
52655278
return x509;
52665279
}
52675280

0 commit comments

Comments
 (0)