[PATCH] lib: ecdsa: fix prevent memory leak in ecdsa_add_verify_data
Anton Moryakov
ant.v.moryakov at gmail.com
Tue Feb 25 14:49:59 CET 2025
- Ensure `free_ctx` is called in both error and success paths.
- Fix memory leak in `ctx.signature` when `do_add` fails."
Triggers found by static analyzer Svace.
Signed-off-by: Anton Moryakov <ant.v.moryakov at gmail.com>
---
lib/ecdsa/ecdsa-libcrypto.c | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/lib/ecdsa/ecdsa-libcrypto.c b/lib/ecdsa/ecdsa-libcrypto.c
index 1c5dde6069..f0095e9dbc 100644
--- a/lib/ecdsa/ecdsa-libcrypto.c
+++ b/lib/ecdsa/ecdsa-libcrypto.c
@@ -363,8 +363,10 @@ int ecdsa_add_verify_data(struct image_sign_info *info, void *fdt)
ret = prepare_ctx(&ctx, info);
if (ret >= 0) {
ret = do_add(&ctx, fdt, fdt_key_name, info);
- if (ret < 0)
- ret = ret == -FDT_ERR_NOSPACE ? -ENOSPC : -EIO;
+ if (ret < 0) {
+ free_ctx(&ctx);
+ return ret == -FDT_ERR_NOSPACE ? -ENOSPC : -EIO;
+ }
}
free_ctx(&ctx);
--
2.30.2
More information about the U-Boot
mailing list