mirror of
git://git.gnupg.org/gnupg.git
synced 2025-01-03 12:11:33 +01:00
g10: Enumerated keys for decryption should be unique.
* g10/getkey.c (enum_secret_keys): Collecting keys in the context, check duplicate to make sure returning only unique keys. * g10/pubkey-enc.c (get_session_key): Now, it's the responsibility of enum_secret_keys to free keys. -- Signed-off-by: NIIBE Yutaka <gniibe@fsij.org>
This commit is contained in:
parent
fed3e10121
commit
c03a3eb01d
25
g10/getkey.c
25
g10/getkey.c
@ -3950,6 +3950,7 @@ enum_secret_keys (ctrl_t ctrl, void **context, PKT_public_key *sk)
|
||||
kbnode_t keyblock;
|
||||
kbnode_t node;
|
||||
getkey_ctx_t ctx;
|
||||
pubkey_t results;
|
||||
} *c = *context;
|
||||
|
||||
if (!c)
|
||||
@ -3964,6 +3965,7 @@ enum_secret_keys (ctrl_t ctrl, void **context, PKT_public_key *sk)
|
||||
if (!sk)
|
||||
{
|
||||
/* Free the context. */
|
||||
pubkeys_free (c->results);
|
||||
release_kbnode (c->keyblock);
|
||||
getkey_end (ctrl, c->ctx);
|
||||
xfree (c);
|
||||
@ -4066,8 +4068,31 @@ enum_secret_keys (ctrl_t ctrl, void **context, PKT_public_key *sk)
|
||||
if (c->node->pkt->pkttype == PKT_PUBLIC_KEY
|
||||
|| c->node->pkt->pkttype == PKT_PUBLIC_SUBKEY)
|
||||
{
|
||||
pubkey_t r;
|
||||
|
||||
/* Skip this candidate if it's already enumerated. */
|
||||
for (r = c->results; r; r = r->next)
|
||||
if (!cmp_public_keys (r->pk, c->node->pkt->pkt.public_key))
|
||||
break;
|
||||
if (r)
|
||||
continue;
|
||||
|
||||
copy_public_key (sk, c->node->pkt->pkt.public_key);
|
||||
c->node = c->node->next;
|
||||
|
||||
r = xtrycalloc (1, sizeof (*r));
|
||||
if (!r)
|
||||
{
|
||||
err = gpg_error_from_syserror ();
|
||||
free_public_key (sk);
|
||||
return err;
|
||||
}
|
||||
|
||||
r->pk = sk;
|
||||
r->keyblock = NULL;
|
||||
r->next = c->results;
|
||||
c->results = r;
|
||||
|
||||
return 0; /* Found. */
|
||||
}
|
||||
}
|
||||
|
@ -87,7 +87,6 @@ get_session_key (ctrl_t ctrl, struct pubkey_enc_list *list, DEK *dek)
|
||||
{
|
||||
struct pubkey_enc_list *k;
|
||||
|
||||
free_public_key (sk);
|
||||
sk = xmalloc_clear (sizeof *sk);
|
||||
rc = enum_secret_keys (ctrl, &enum_context, sk);
|
||||
if (rc)
|
||||
@ -156,7 +155,6 @@ get_session_key (ctrl_t ctrl, struct pubkey_enc_list *list, DEK *dek)
|
||||
}
|
||||
}
|
||||
enum_secret_keys (ctrl, &enum_context, NULL); /* free context */
|
||||
free_public_key (sk);
|
||||
|
||||
if (DBG_CLOCK)
|
||||
log_clock ("get_session_key leave");
|
||||
|
Loading…
x
Reference in New Issue
Block a user