1
0
mirror of git://git.gnupg.org/gnupg.git synced 2025-04-17 15:44:34 +02:00

gpg: Robust error handling for SCD READKEY.

* g10/keygen.c (ask_algo): List the card key only when it's valid.

--

GnuPG-bug-id: 7309
Signed-off-by: NIIBE Yutaka <gniibe@fsij.org>
This commit is contained in:
NIIBE Yutaka 2024-10-01 10:55:11 +09:00 committed by Werner Koch
parent 99069e9f6b
commit 6022f10da3
No known key found for this signature in database
GPG Key ID: E3FDFF218E45B72B

View File

@ -2478,12 +2478,14 @@ ask_algo (ctrl_t ctrl, int addmode, int *r_subkey_algo, unsigned int *r_usage,
const char *keyref = kpi->idstr; const char *keyref = kpi->idstr;
int any = 0; int any = 0;
if (keyref if (!keyref)
&& !agent_scd_readkey (ctrl, keyref, &s_pkey, NULL)) continue;
{
if (!agent_scd_readkey (ctrl, keyref, &s_pkey, NULL))
continue;
algostr = pubkey_algo_string (s_pkey, &algoid); algostr = pubkey_algo_string (s_pkey, &algoid);
gcry_sexp_release (s_pkey); gcry_sexp_release (s_pkey);
}
/* We need to tweak the algo in case GCRY_PK_ECC is /* We need to tweak the algo in case GCRY_PK_ECC is
* returned because pubkey_algo_string is not aware * returned because pubkey_algo_string is not aware
@ -2556,9 +2558,9 @@ ask_algo (ctrl_t ctrl, int addmode, int *r_subkey_algo, unsigned int *r_usage,
for (count=1,kpi=keypairlist; kpi; kpi = kpi->next, count++) for (count=1,kpi=keypairlist; kpi; kpi = kpi->next, count++)
if (count == selection) if (count == selection)
break; break;
if (!kpi) if (!kpi || !kpi->algo)
{ {
/* Just in case COUNT is zero (no keys). */ /* Just in case no good key. */
free_keypair_info (keypairlist); free_keypair_info (keypairlist);
goto ask_again; goto ask_again;
} }