aboutsummaryrefslogtreecommitdiffstats
path: root/g10/keygen.c
diff options
context:
space:
mode:
authorJakub Jelen <[email protected]>2021-05-20 08:13:51 +0000
committerWerner Koch <[email protected]>2021-05-20 11:38:39 +0000
commit2af7bb2295cda5377546cedd0c906a3cff4d2427 (patch)
tree3e912bccb258941b085959201b6c81b8940339a5 /g10/keygen.c
parentdirmgr: clean up memory on error code paths (diff)
downloadgnupg-2af7bb2295cda5377546cedd0c906a3cff4d2427.tar.gz
gnupg-2af7bb2295cda5377546cedd0c906a3cff4d2427.zip
g10: Fix memory leaks
* g10/card-util.c (change_pin): free answer on errors (ask_card_keyattr): free answer on error * g10/cpr.c (do_get_from_fd): free string * g10/gpg.c (check_permissions): free dir on weird error * g10/import.c (append_new_uid): release knode * g10/keyedit.c (menu_set_keyserver_url): free answer (menu_set_keyserver_url): free user * g10/keygen.c (print_status_key_not_created): move allocation after sanity check (ask_expire_interval): free answer (card_store_key_with_backup): goto leave instaed of return * g10/keyserver.c (parse_keyserver_uri): goto fail instead of return * g10/revoke.c (gen_desig_revoke): release kdbhd (gen_desig_revoke): free answer * g10/tofu.c (ask_about_binding): free sqerr and response * g10/trustdb.c (ask_ownertrust): free pk -- Signed-off-by: Jakub Jelen <[email protected]> Further changes: * g10/card-util.c (change_pin): Do not set answer to NULL. * g10/keyedit.c(menu_set_keyserver_url): Use !func() pattern. Signed-off-by: Werner Koch <[email protected]> GnuPG-bug-id: 5393
Diffstat (limited to 'g10/keygen.c')
-rw-r--r--g10/keygen.c15
1 files changed, 11 insertions, 4 deletions
diff --git a/g10/keygen.c b/g10/keygen.c
index 5d85c05d4..f1e4d3638 100644
--- a/g10/keygen.c
+++ b/g10/keygen.c
@@ -237,12 +237,13 @@ print_status_key_not_created (const char *handle)
static gpg_error_t
write_uid (kbnode_t root, const char *s)
{
- PACKET *pkt = xmalloc_clear (sizeof *pkt);
+ PACKET *pkt = NULL;
size_t n = strlen (s);
if (n > MAX_UID_PACKET_LENGTH - 10)
return gpg_error (GPG_ERR_INV_USER_ID);
+ pkt = xmalloc_clear (sizeof *pkt);
pkt->pkttype = PKT_USER_ID;
pkt->pkt.user_id = xmalloc_clear (sizeof *pkt->pkt.user_id + n);
pkt->pkt.user_id->len = n;
@@ -2860,7 +2861,10 @@ ask_expire_interval(int object,const char *def_expire)
xfree(prompt);
if(*answer=='\0')
- answer=xstrdup(def_expire);
+ {
+ xfree (answer);
+ answer = xstrdup (def_expire);
+ }
}
cpr_kill_prompt();
trim_spaces(answer);
@@ -5238,12 +5242,15 @@ card_store_key_with_backup (ctrl_t ctrl, PKT_public_key *sub_psk,
epoch2isotime (timestamp, (time_t)sk->timestamp);
err = hexkeygrip_from_pk (sk, &hexgrip);
if (err)
- return err;
+ goto leave;
memset(&info, 0, sizeof (info));
rc = agent_scd_getattr ("SERIALNO", &info);
if (rc)
- return (gpg_error_t)rc;
+ {
+ err = (gpg_error_t)rc;
+ goto leave;
+ }
rc = agent_keytocard (hexgrip, 2, 1, info.serialno, timestamp);
xfree (info.serialno);