gpg: The first key should be in candidates.

* g10/getkey.c (get_best_pubkey_byname): Handle the first key
as the initial candidate for the selection.

--

GnuPG-bug-id: 4713
Signed-off-by: NIIBE Yutaka <gniibe@fsij.org>
This commit is contained in:
NIIBE Yutaka 2019-10-09 09:45:11 +09:00
parent 2b922465cb
commit 7535f1d47a
1 changed files with 8 additions and 1 deletions

View File

@ -1354,6 +1354,8 @@ get_best_pubkey_byname (ctrl_t ctrl, enum get_pubkey_modes mode,
int is_mbox = is_valid_mailbox (name);
int wkd_tried = 0;
log_assert (ret_keyblock != NULL);
if (retctx)
*retctx = NULL;
@ -1416,7 +1418,10 @@ get_best_pubkey_byname (ctrl_t ctrl, enum get_pubkey_modes mode,
struct pubkey_cmp_cookie new = { 0 };
kbnode_t new_keyblock;
while (getkey_next (ctrl, ctx, &new.key, &new_keyblock) == 0)
copy_public_key (&new.key, (*ret_keyblock)->pkt->pkt.public_key);
new_keyblock = clone_kbnode (*ret_keyblock);
do
{
int diff = pubkey_cmp (ctrl, name, &best, &new, new_keyblock);
release_kbnode (new_keyblock);
@ -1441,6 +1446,8 @@ get_best_pubkey_byname (ctrl_t ctrl, enum get_pubkey_modes mode,
}
new.uid = NULL;
}
while (getkey_next (ctrl, ctx, &new.key, &new_keyblock) == 0);
getkey_end (ctrl, ctx);
ctx = NULL;
free_user_id (best.uid);