Merge pull request #6892 from embhorn/gh6890
Add error reporting to loadX509orX509REQFromBuffer
This commit is contained in:
commit
2f920b5cc4
23
src/x509.c
23
src/x509.c
@ -5218,7 +5218,7 @@ 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;
|
||||
|
||||
@ -5226,7 +5226,8 @@ static WOLFSSL_X509* loadX509orX509REQFromBuffer(
|
||||
|
||||
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
|
||||
@ -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);
|
||||
@ -5277,6 +5286,10 @@ static WOLFSSL_X509* loadX509orX509REQFromBuffer(
|
||||
FreeDer(&der);
|
||||
}
|
||||
|
||||
if (ret != 0) {
|
||||
WOLFSSL_ERROR(ret);
|
||||
}
|
||||
|
||||
return x509;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user