From ed6cadd6c72e376337158e83ce3b9bc1c70c1f6a Mon Sep 17 00:00:00 2001 From: Dmitry Belyavskiy Date: Thu, 21 Mar 2024 16:37:37 +0100 Subject: [PATCH 1/2] Fix potential memory leak --- tools/credman.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tools/credman.c b/tools/credman.c index a0a3149d..dc239d0b 100644 --- a/tools/credman.c +++ b/tools/credman.c @@ -127,6 +127,8 @@ print_rk(const fido_credman_rk_t *rk, size_t idx) if (base64_encode(fido_cred_id_ptr(cred), fido_cred_id_len(cred), &id) < 0 || base64_encode(fido_cred_user_id_ptr(cred), fido_cred_user_id_len(cred), &user_id) < 0) { + free(user_id); + free(id); warnx("output error"); return -1; } From 6a824f56a3d3c6c02f55ad9de83d9d66c3eca3f9 Mon Sep 17 00:00:00 2001 From: Ludvig Michaelsson Date: Fri, 22 Mar 2024 10:26:43 +0100 Subject: [PATCH 2/2] tools: tweak previous --- tools/credman.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/tools/credman.c b/tools/credman.c index dc239d0b..9f6072f7 100644 --- a/tools/credman.c +++ b/tools/credman.c @@ -119,6 +119,7 @@ print_rk(const fido_credman_rk_t *rk, size_t idx) char *user_id = NULL; const char *type; const char *prot; + int r = -1; if ((cred = fido_credman_rk(rk, idx)) == NULL) { warnx("fido_credman_rk"); @@ -127,10 +128,8 @@ print_rk(const fido_credman_rk_t *rk, size_t idx) if (base64_encode(fido_cred_id_ptr(cred), fido_cred_id_len(cred), &id) < 0 || base64_encode(fido_cred_user_id_ptr(cred), fido_cred_user_id_len(cred), &user_id) < 0) { - free(user_id); - free(id); warnx("output error"); - return -1; + goto out; } type = cose_string(fido_cred_type(cred)); @@ -139,10 +138,12 @@ print_rk(const fido_credman_rk_t *rk, size_t idx) printf("%02u: %s %s %s %s %s\n", (unsigned)idx, id, fido_cred_display_name(cred), user_id, type, prot); + r = 0; +out: free(user_id); free(id); - return 0; + return r; } int