diff options
| author | Anton Moryakov <[email protected]> | 2025-02-07 00:47:59 +0300 |
|---|---|---|
| committer | Tom Rini <[email protected]> | 2025-03-03 14:24:48 -0600 |
| commit | 9943015f1b39fcb2de16ee72f1599c342620c561 (patch) | |
| tree | 395e9e29dea4fef314b58299a7dabec23a5dbbf2 | |
| parent | 1bc125becaa5e612923a9cfa1ec8e9f0b88ac28e (diff) | |
lib: ecdsa: fix prevent memory leak in ecdsa_add_verify_data
- 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 <[email protected]>
| -rw-r--r-- | lib/ecdsa/ecdsa-libcrypto.c | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/lib/ecdsa/ecdsa-libcrypto.c b/lib/ecdsa/ecdsa-libcrypto.c index 1c5dde60691..f0095e9dbcf 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); |
