summaryrefslogtreecommitdiffstats
path: root/sm/server.c
diff options
context:
space:
mode:
authorJakub Jelen <jjelen@redhat.com>2021-04-12 14:05:17 +0200
committerWerner Koch <wk@gnupg.org>2021-05-20 13:51:47 +0200
commite6132bc9f41727ea1abe2d6298610223c11639a2 (patch)
tree6d76b81dc687c9dd7627e5495dd1cf815ad3be09 /sm/server.c
parentg10: Fix memory leaks (diff)
downloadgnupg2-e6132bc9f41727ea1abe2d6298610223c11639a2.tar.xz
gnupg2-e6132bc9f41727ea1abe2d6298610223c11639a2.zip
sm: Avoid memory leaks and double double-free
* sm/certcheck.c (extract_pss_params): Avoid double free * sm/decrypt.c (gpgsm_decrypt): goto leave instead of return * sm/encrypt.c (encrypt_dek): release s_pkey * sm/server.c (cmd_export): free list (do_listkeys): free lists -- Signed-off-by: Jakub Jelen <jjelen@redhat.com> GnuPG-bug-id: 5393
Diffstat (limited to 'sm/server.c')
-rw-r--r--sm/server.c26
1 files changed, 21 insertions, 5 deletions
diff --git a/sm/server.c b/sm/server.c
index 874f0db89..2a6d7c381 100644
--- a/sm/server.c
+++ b/sm/server.c
@@ -724,8 +724,13 @@ cmd_export (assuan_context_t ctx, char *line)
if (opt_secret)
{
- if (!list || !*list->d)
+ if (!list)
return set_error (GPG_ERR_NO_DATA, "No key given");
+ if (!*list->d)
+ {
+ free_strlist (list);
+ return set_error (GPG_ERR_NO_DATA, "No key given");
+ }
if (list->next)
return set_error (GPG_ERR_TOO_MANY, "Only one key allowed");
}
@@ -1014,17 +1019,27 @@ do_listkeys (assuan_context_t ctx, char *line, int mode)
int outfd = translate_sys2libc_fd (assuan_get_output_fd (ctx), 1);
if ( outfd == -1 )
- return set_error (GPG_ERR_ASS_NO_OUTPUT, NULL);
+ {
+ free_strlist (list);
+ return set_error (GPG_ERR_ASS_NO_OUTPUT, NULL);
+ }
fp = es_fdopen_nc (outfd, "w");
if (!fp)
- return set_error (gpg_err_code_from_syserror (), "es_fdopen() failed");
+ {
+ free_strlist (list);
+ return set_error (gpg_err_code_from_syserror (),
+ "es_fdopen() failed");
+ }
}
else
{
fp = es_fopencookie (ctx, "w", data_line_cookie_functions);
if (!fp)
- return set_error (GPG_ERR_ASS_GENERAL,
- "error setting up a data stream");
+ {
+ free_strlist (list);
+ return set_error (GPG_ERR_ASS_GENERAL,
+ "error setting up a data stream");
+ }
}
ctrl->with_colons = 1;
@@ -1034,6 +1049,7 @@ do_listkeys (assuan_context_t ctx, char *line, int mode)
if (ctrl->server_local->list_external)
listmode |= (1<<7);
err = gpgsm_list_keys (assuan_get_pointer (ctx), list, fp, listmode);
+
free_strlist (list);
es_fclose (fp);
if (ctrl->server_local->list_to_output)