From 76e0a8666be6cd38a59118026260807f54239eae Mon Sep 17 00:00:00 2001 From: Guido Vranken Date: Sun, 6 Jun 2021 03:12:53 +0200 Subject: [PATCH 1/3] Catch allocation failure in DecodeResponseData --- wolfcrypt/src/asn.c | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/wolfcrypt/src/asn.c b/wolfcrypt/src/asn.c index 9df7aaa3d..3ee47af19 100644 --- a/wolfcrypt/src/asn.c +++ b/wolfcrypt/src/asn.c @@ -17472,12 +17472,20 @@ static int DecodeResponseData(byte* source, if (single->next == NULL) { return MEMORY_E; } - single = single->next; - XMEMSET(single, 0, sizeof(OcspEntry)); - single->status = (CertStatus*)XMALLOC(sizeof(CertStatus), + XMEMSET(single->next, 0, sizeof(OcspEntry)); + + single->next->status = (CertStatus*)XMALLOC(sizeof(CertStatus), resp->heap, DYNAMIC_TYPE_OCSP_STATUS); - XMEMSET(single->status, 0, sizeof(CertStatus)); - single->isDynamic = 1; + if ( single->next->status == NULL ) { + XFREE(single->next, resp->heap, DYNAMIC_TYPE_OCSP_ENTRY); + single->next = NULL; + return MEMORY_E; + } + XMEMSET(single->next->status, 0, sizeof(CertStatus)); + + single->next->isDynamic = 1; + + single = single->next; } } From 1af3f482cb74b56de1fdead6c13ffc1f6f984d0f Mon Sep 17 00:00:00 2001 From: Guido Vranken Date: Sun, 6 Jun 2021 19:52:15 +0200 Subject: [PATCH 2/3] Catch allocation failure in ASNToHexString --- wolfcrypt/src/asn.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/wolfcrypt/src/asn.c b/wolfcrypt/src/asn.c index 3ee47af19..b46f7812d 100644 --- a/wolfcrypt/src/asn.c +++ b/wolfcrypt/src/asn.c @@ -16166,6 +16166,10 @@ static int ASNToHexString(const byte* input, word32* inOutIdx, char** out, } str = (char*)XMALLOC(len * 2 + 1, heap, heapType); + if (str == NULL) { + return MEMORY_E; + } + for (i=0; i Date: Mon, 7 Jun 2021 03:20:16 +0200 Subject: [PATCH 3/3] Remove excess space characters --- wolfcrypt/src/asn.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wolfcrypt/src/asn.c b/wolfcrypt/src/asn.c index b46f7812d..373c71975 100644 --- a/wolfcrypt/src/asn.c +++ b/wolfcrypt/src/asn.c @@ -17480,7 +17480,7 @@ static int DecodeResponseData(byte* source, single->next->status = (CertStatus*)XMALLOC(sizeof(CertStatus), resp->heap, DYNAMIC_TYPE_OCSP_STATUS); - if ( single->next->status == NULL ) { + if (single->next->status == NULL) { XFREE(single->next, resp->heap, DYNAMIC_TYPE_OCSP_ENTRY); single->next = NULL; return MEMORY_E;