Pārlūkot izejas kodu

fix missing mutex unlock

Fixes a missing mutex unlock on an out of memory error
in ltc_ecc_fp_save_state().

Originates from: https://github.com/OP-TEE/optee_os/commit/4af447d4084e293800d4e463d65003c016b91f29

Fixes #571

Comment by sj:
This patch version slightly deviates from the original patch to OP-TEE
since we don't call `XFREE(NULL)` as there exist implementations of
`free()` that don't support it.

Signed-off-by: Ryan Cai <[email protected]>
Reviewed-by: Jens Wiklander <[email protected]>
Modified-by: Steffen Jaeckel <[email protected]>
ycaibb 4 gadi atpakaļ
vecāks
revīzija
ee24a31ae1
1 mainītis faili ar 3 papildinājumiem un 1 dzēšanām
  1. 3 1
      src/math/fp/ltc_ecc_fp_mulmod.c

+ 3 - 1
src/math/fp/ltc_ecc_fp_mulmod.c

@@ -1429,8 +1429,10 @@ int ltc_ecc_fp_save_state(unsigned char **out, unsigned long *outlen)
     * and the mu INTEGER
     */
    cache_entry = XCALLOC(FP_ENTRIES*(2*(1U<<FP_LUT)+4)+3, sizeof(ltc_asn1_list));
-   if (cache_entry == NULL)
+   if (cache_entry == NULL) {
+      LTC_MUTEX_UNLOCK(&ltc_ecc_fp_lock);
       return CRYPT_MEM;
+   }
    j = 1;   /* handle the zero'th element later */
 
    LTC_SET_ASN1(cache_entry, j++, LTC_ASN1_SHORT_INTEGER, &fp_entries, 1);