diff options
author | Jakub Jelen <jjelen@redhat.com> | 2021-05-20 10:13:51 +0200 |
---|---|---|
committer | Werner Koch <wk@gnupg.org> | 2021-05-20 13:38:39 +0200 |
commit | 2af7bb2295cda5377546cedd0c906a3cff4d2427 (patch) | |
tree | 3e912bccb258941b085959201b6c81b8940339a5 /g10 | |
parent | dirmgr: clean up memory on error code paths (diff) | |
download | gnupg2-2af7bb2295cda5377546cedd0c906a3cff4d2427.tar.xz gnupg2-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 <jjelen@redhat.com>
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 <wk@gnupg.org>
GnuPG-bug-id: 5393
Diffstat (limited to 'g10')
-rw-r--r-- | g10/card-util.c | 12 | ||||
-rw-r--r-- | g10/cpr.c | 6 | ||||
-rw-r--r-- | g10/gpg.c | 1 | ||||
-rw-r--r-- | g10/import.c | 5 | ||||
-rw-r--r-- | g10/keyedit.c | 10 | ||||
-rw-r--r-- | g10/keygen.c | 15 | ||||
-rw-r--r-- | g10/keyserver.c | 2 | ||||
-rw-r--r-- | g10/revoke.c | 6 | ||||
-rw-r--r-- | g10/tofu.c | 4 | ||||
-rw-r--r-- | g10/trustdb.c | 1 |
10 files changed, 50 insertions, 12 deletions
diff --git a/g10/card-util.c b/g10/card-util.c index 36f096f06..e79e9e508 100644 --- a/g10/card-util.c +++ b/g10/card-util.c @@ -140,7 +140,10 @@ change_pin (int unblock_v2, int allow_admin) answer = cpr_get("cardutil.change_pin.menu",_("Your selection? ")); cpr_kill_prompt(); if (strlen (answer) != 1) - continue; + { + xfree (answer); + continue; + } if (*answer == '1') { @@ -185,8 +188,10 @@ change_pin (int unblock_v2, int allow_admin) } else if (*answer == 'q' || *answer == 'Q') { + xfree (answer); break; } + xfree (answer); } agent_release_card_info (&info); @@ -1450,7 +1455,10 @@ ask_card_keyattr (int keyno, const struct key_attr *current) algo = *answer? atoi (answer) : 0; if (!*answer || algo == 1 || algo == 2) - break; + { + xfree (answer); + break; + } else tty_printf (_("Invalid selection.\n")); } @@ -527,7 +527,11 @@ do_get_from_fd ( const char *keyword, int hidden, int getbool ) write_status (STATUS_GOT_IT); if (getbool) /* Fixme: is this correct??? */ - return (string[0] == 'Y' || string[0] == 'y') ? "" : NULL; + { + char *rv = (string[0] == 'Y' || string[0] == 'y') ? "" : NULL; + xfree (string); + return rv; + } return string; } @@ -1601,6 +1601,7 @@ check_permissions (const char *path, int item) if (gnupg_stat (dir,&dirbuf) || !S_ISDIR (dirbuf.st_mode)) { /* Weird error */ + xfree(dir); ret=1; goto end; } diff --git a/g10/import.c b/g10/import.c index 821ddf0d4..951c33d81 100644 --- a/g10/import.c +++ b/g10/import.c @@ -4524,7 +4524,10 @@ append_new_uid (unsigned int options, err = insert_key_origin_uid (n->pkt->pkt.user_id, curtime, origin, url); if (err) - return err; + { + release_kbnode (n); + return err; + } } if (n_where) diff --git a/g10/keyedit.c b/g10/keyedit.c index 531d3e128..7255676e7 100644 --- a/g10/keyedit.c +++ b/g10/keyedit.c @@ -5306,8 +5306,11 @@ menu_set_keyserver_url (ctrl_t ctrl, const char *url, kbnode_t pub_keyblock) } } - if (ascii_strcasecmp (answer, "none") == 0) - uri = NULL; + if (!ascii_strcasecmp (answer, "none")) + { + xfree (answer); + uri = NULL; + } else { struct keyserver_spec *keyserver = NULL; @@ -5379,12 +5382,14 @@ menu_set_keyserver_url (ctrl_t ctrl, const char *url, kbnode_t pub_keyblock) uri ? _("Are you sure you want to replace it? (y/N) ") : _("Are you sure you want to delete it? (y/N) "))) + xfree (user); continue; } else if (uri == NULL) { /* There is no current keyserver URL, so there is no point in trying to un-set it. */ + xfree (user); continue; } @@ -5397,6 +5402,7 @@ menu_set_keyserver_url (ctrl_t ctrl, const char *url, kbnode_t pub_keyblock) log_error ("update_keysig_packet failed: %s\n", gpg_strerror (rc)); xfree (uri); + xfree (user); return 0; } /* replace the packet */ 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); diff --git a/g10/keyserver.c b/g10/keyserver.c index c56021691..a20ebf24e 100644 --- a/g10/keyserver.c +++ b/g10/keyserver.c @@ -284,7 +284,7 @@ parse_keyserver_uri (const char *string,int require_scheme) if(*idx=='\0' || *idx=='[') { if(require_scheme) - return NULL; + goto fail; /* Assume HKP if there is no scheme */ assume_hkp=1; diff --git a/g10/revoke.c b/g10/revoke.c index c0a003b6f..d6cbf93cb 100644 --- a/g10/revoke.c +++ b/g10/revoke.c @@ -435,6 +435,7 @@ gen_desig_revoke (ctrl_t ctrl, const char *uname, strlist_t locusr) iobuf_close(out); release_revocation_reason_info( reason ); release_armor_context (afx); + keydb_release (kdbhd); return rc; } @@ -804,7 +805,10 @@ ask_revocation_reason( int key_rev, int cert_rev, int hint ) trim_spaces( answer ); cpr_kill_prompt(); if( *answer == 'q' || *answer == 'Q') - return NULL; /* cancel */ + { + xfree (answer); + return NULL; /* cancel */ + } if( hint && !*answer ) n = hint; else if(!digitp( answer ) ) diff --git a/g10/tofu.c b/g10/tofu.c index f49083844..83786a08d 100644 --- a/g10/tofu.c +++ b/g10/tofu.c @@ -1687,6 +1687,8 @@ ask_about_binding (ctrl_t ctrl, GPGSQL_ARG_END); if (rc) { + sqlite3_free (sqerr); + sqerr = NULL; rc = gpg_error (GPG_ERR_GENERAL); break; } @@ -1972,6 +1974,7 @@ ask_about_binding (ctrl_t ctrl, else if (!response[0]) /* Default to unknown. Don't save it. */ { + xfree (response); tty_printf (_("Defaulting to unknown.\n")); *policy = TOFU_POLICY_UNKNOWN; break; @@ -1983,6 +1986,7 @@ ask_about_binding (ctrl_t ctrl, if (choice) { int c = ((size_t) choice - (size_t) choices) / 2; + xfree (response); switch (c) { diff --git a/g10/trustdb.c b/g10/trustdb.c index 43bce0769..9ef4644bf 100644 --- a/g10/trustdb.c +++ b/g10/trustdb.c @@ -1430,6 +1430,7 @@ ask_ownertrust (ctrl_t ctrl, u32 *kid, int minimum) { log_error (_("public key %s not found: %s\n"), keystr(kid), gpg_strerror (rc) ); + free_public_key (pk); return TRUST_UNKNOWN; } |