From b3a1badecf7155a795de5239a6ba19b70ec0c6a9 Mon Sep 17 00:00:00 2001 From: Andras Fekete Date: Mon, 14 Aug 2023 17:02:59 -0400 Subject: [PATCH 1/2] Check the return value --- wolfcrypt/src/asn.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/wolfcrypt/src/asn.c b/wolfcrypt/src/asn.c index 336934f9b..eda4ac94a 100644 --- a/wolfcrypt/src/asn.c +++ b/wolfcrypt/src/asn.c @@ -31698,9 +31698,12 @@ int StoreECC_DSA_Sig(byte* out, word32* outLen, mp_int* r, mp_int* s) } if (ret == 0) { /* Encode DSA signature into buffer. */ - SetASN_Items(dsaSigASN, dataASN, dsaSigASN_Length, out); - /* Set the actual encoding size. */ - *outLen = (word32)sz; + ret = SetASN_Items(dsaSigASN, dataASN, dsaSigASN_Length, out); + if ((ret >= 0) && (ret == sz)) { + /* Set the actual encoding size. */ + *outLen = (word32)sz; + ret = 0; + } } return ret; From f1b4387eca25b82a73a293de36316df521f814b3 Mon Sep 17 00:00:00 2001 From: Andras Fekete Date: Tue, 15 Aug 2023 15:00:06 -0400 Subject: [PATCH 2/2] Return a failure if the sizes don't match --- wolfcrypt/src/asn.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/wolfcrypt/src/asn.c b/wolfcrypt/src/asn.c index eda4ac94a..9bbdf2b79 100644 --- a/wolfcrypt/src/asn.c +++ b/wolfcrypt/src/asn.c @@ -31699,10 +31699,14 @@ int StoreECC_DSA_Sig(byte* out, word32* outLen, mp_int* r, mp_int* s) if (ret == 0) { /* Encode DSA signature into buffer. */ ret = SetASN_Items(dsaSigASN, dataASN, dsaSigASN_Length, out); - if ((ret >= 0) && (ret == sz)) { - /* Set the actual encoding size. */ - *outLen = (word32)sz; - ret = 0; + if (ret >= 0) { + if (ret == sz) { + /* Set the actual encoding size. */ + *outLen = (word32)sz; + ret = 0; + } else { + ret = BAD_STATE_E; + } } }