From 195ca2b3f04818c744c57b298faf523bafabdcea Mon Sep 17 00:00:00 2001 From: TakayukiMatsuo Date: Thu, 3 Jun 2021 20:02:48 +0900 Subject: [PATCH] Add corner test cases for EVP_EncodeFinal and EVP_DecodeFinal --- tests/api.c | 16 ++++++++++++++++ wolfcrypt/src/evp.c | 5 +++-- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/tests/api.c b/tests/api.c index 9b0c30fff..424d82938 100644 --- a/tests/api.c +++ b/tests/api.c @@ -2615,6 +2615,16 @@ static void test_wolfSSL_EVP_EncodeUpdate(void) AssertIntEQ(XSTRNCMP( (const char*)encOutBuff,(const char*)enc2,sizeof(enc2) ),0); + /* test with illeagal parameters */ + outl = 1; + EVP_EncodeFinal(NULL, encOutBuff + outl, &outl); + AssertIntEQ(outl, 0); + outl = 1; + EVP_EncodeFinal(ctx, NULL, &outl); + AssertIntEQ(outl, 0); + EVP_EncodeFinal(ctx, encOutBuff + outl, NULL); + EVP_EncodeFinal(NULL, NULL, NULL); + EVP_ENCODE_CTX_free(ctx); printf(resultFmt, passed); #endif /* OPENSSL_EXTRA && WOLFSSL_BASE64_ENCODE*/ @@ -2852,6 +2862,12 @@ static void test_wolfSSL_EVP_DecodeUpdate(void) AssertIntEQ(outl,sizeof(plain4)-1); + /* test with illegal parameters */ + AssertIntEQ(EVP_DecodeFinal(NULL,decOutBuff + outl,&outl), -1); + AssertIntEQ(EVP_DecodeFinal(ctx,NULL,&outl), -1); + AssertIntEQ(EVP_DecodeFinal(ctx,decOutBuff + outl, NULL), -1); + AssertIntEQ(EVP_DecodeFinal(NULL,NULL, NULL), -1); + EVP_DecodeFinal( ctx, decOutBuff + outl, diff --git a/wolfcrypt/src/evp.c b/wolfcrypt/src/evp.c index 31de9063b..697edf344 100644 --- a/wolfcrypt/src/evp.c +++ b/wolfcrypt/src/evp.c @@ -6958,9 +6958,10 @@ int wolfSSL_EVP_EncodeUpdate(WOLFSSL_EVP_ENCODE_CTX* ctx, outsz = BASE64_ENCODE_RESULT_BLOCK_SIZE + 1; res = Base64_Encode(ctx->data, BASE64_ENCODE_BLOCK_SIZE, out, &outsz); - ctx->remaining = 0; - if (res == 0) + if (res == 0) { + ctx->remaining = 0; *outl = outsz; + } else return 0; /* return with error */ }