Skip to content

Commit 2f920b5

Browse files
Merge pull request #6892 from embhorn/gh6890
Add error reporting to loadX509orX509REQFromBuffer
2 parents 9810a8c + 962e35a commit 2f920b5

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
@@ -5218,15 +5218,16 @@ static WOLFSSL_X509* loadX509orX509REQFromBuffer(
52185218
const unsigned char* buf, int sz, int format, int type)
52195219
{
52205220

5221-
int ret;
5221+
int ret = 0;
52225222
WOLFSSL_X509* x509 = NULL;
52235223
DerBuffer* der = NULL;
52245224

52255225
WOLFSSL_ENTER("wolfSSL_X509_load_certificate_ex");
52265226

52275227
if (format == WOLFSSL_FILETYPE_PEM) {
52285228
#ifdef WOLFSSL_PEM_TO_DER
5229-
if (PemToDer(buf, sz, type, &der, NULL, NULL, NULL) != 0) {
5229+
ret = PemToDer(buf, sz, type, &der, NULL, NULL, NULL);
5230+
if (ret != 0) {
52305231
FreeDer(&der);
52315232
}
52325233
#else
@@ -5252,20 +5253,28 @@ static WOLFSSL_X509* loadX509orX509REQFromBuffer(
52525253
#ifdef WOLFSSL_SMALL_STACK
52535254
cert = (DecodedCert*)XMALLOC(sizeof(DecodedCert), NULL,
52545255
DYNAMIC_TYPE_DCERT);
5255-
if (cert != NULL)
5256+
if (cert == NULL) {
5257+
ret = MEMORY_ERROR;
5258+
}
5259+
else
52565260
#endif
52575261
{
52585262
InitDecodedCert(cert, der->buffer, der->length, NULL);
5259-
if (ParseCertRelative(cert, type, 0, NULL) == 0) {
5263+
ret = ParseCertRelative(cert, type, 0, NULL);
5264+
if (ret == 0) {
52605265
x509 = (WOLFSSL_X509*)XMALLOC(sizeof(WOLFSSL_X509), NULL,
52615266
DYNAMIC_TYPE_X509);
52625267
if (x509 != NULL) {
52635268
InitX509(x509, 1, NULL);
5264-
if (CopyDecodedToX509(x509, cert) != 0) {
5269+
ret = CopyDecodedToX509(x509, cert);
5270+
if (ret != 0) {
52655271
wolfSSL_X509_free(x509);
52665272
x509 = NULL;
52675273
}
52685274
}
5275+
else {
5276+
ret = MEMORY_ERROR;
5277+
}
52695278
}
52705279

52715280
FreeDecodedCert(cert);
@@ -5277,6 +5286,10 @@ static WOLFSSL_X509* loadX509orX509REQFromBuffer(
52775286
FreeDer(&der);
52785287
}
52795288

5289+
if (ret != 0) {
5290+
WOLFSSL_ERROR(ret);
5291+
}
5292+
52805293
return x509;
52815294
}
52825295

0 commit comments

Comments
 (0)