From 301ade763bdcc8dac5a819f5fc6e9d7d5ac6989b Mon Sep 17 00:00:00 2001 From: Etienne Carriere Date: Thu, 5 Nov 2020 16:36:58 +0100 Subject: core: ltc: fix return value in crypto API SM2 PKA decrypt Fix calloc() failure case in core crypto API function for SM2 PKE decryption. Prior this change the function failed but return 0/OK. This change sets the return value to TEE_ERROR_OUT_OF_MEMORY before reaching the function exit sequence. Fixes: f9a78287dd12 (core: ltc: add support for SM2 PKE) Signed-off-by: Etienne Carriere Reviewed-by: Jerome Forissier --- core/lib/libtomcrypt/sm2-pke.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'core') diff --git a/core/lib/libtomcrypt/sm2-pke.c b/core/lib/libtomcrypt/sm2-pke.c index 9d1d8958..ae189cc4 100644 --- a/core/lib/libtomcrypt/sm2-pke.c +++ b/core/lib/libtomcrypt/sm2-pke.c @@ -246,8 +246,10 @@ TEE_Result sm2_ltc_pke_decrypt(struct ecc_keypair *key, const uint8_t *src, *dst_len = out_len; if (out_len < C2_len) { eom = calloc(1, C2_len - out_len); - if (!eom) + if (!eom) { + res = TEE_ERROR_OUT_OF_MEMORY; goto out; + } for (i = out_len; i < C2_len; i++) eom[i - out_len] = src[C1_len + i] ^ t[i]; } -- cgit v1.2.3