From 0cce370f97a73be0d2527c0aea85e673d6984240 Mon Sep 17 00:00:00 2001 From: Brett Nicholas <7547222+bigbrett@users.noreply.github.com> Date: Wed, 23 Oct 2024 15:26:22 -0600 Subject: [PATCH] fix memory error in server-side ECC verify --- src/wh_server_crypto.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/wh_server_crypto.c b/src/wh_server_crypto.c index 600ff77..d1c9b0a 100644 --- a/src/wh_server_crypto.c +++ b/src/wh_server_crypto.c @@ -697,7 +697,7 @@ static int _HandleEccVerify(whServerContext* ctx, whPacket* packet, byte* res_pub = (uint8_t*)(res + 1); word32 max_size = (word32)(WOLFHSM_CFG_COMM_DATA_LEN - (res_pub - (uint8_t*)packet)); - uint16_t pub_size = 0; + uint32_t pub_size = 0; int result; /* init public key */ @@ -712,11 +712,14 @@ static int _HandleEccVerify(whServerContext* ctx, whPacket* packet, if ( (ret == 0) && (export_pub_key != 0) ) { /* Export the public key to the result message*/ - pub_size = wc_EccPublicKeyToDer(key, (byte*)res_pub, + ret = wc_EccPublicKeyToDer(key, (byte*)res_pub, max_size, 1); - if (pub_size < 0) { + if (ret < 0) { /* Problem dumping the public key. Set to 0 length */ pub_size = 0; + } else { + pub_size = ret; + ret = 0; } } }