From 4ba11251aff578394000bf480f47160f0879c763 Mon Sep 17 00:00:00 2001 From: Justus Winter Date: Mon, 25 Jul 2016 12:41:28 +0200 Subject: g10: Fix key import statistics. 'transfer_secret_keys' collects statistics on a subkey-basis, while the other code does not. This leads to inflated numbers when importing secret keys. E.g. 'count' is incremented by the main parsing loop in 'import', and again in 'transfer_secret_keys', leading to a total of 3 if one key with two secret subkeys is imported. * g10/import.c (import_secret_one): Adjust to the fact that 'transfer_secret_keys' collects subkey statistics. * tests/openpgp/Makefile.am (TESTS): Add new test. * tests/openpgp/issue2346.scm: New file. * tests/openpgp/samplekeys/issue2346.gpg: Likewise. GnuPG-bug-id: 2346 Signed-off-by: Justus Winter --- g10/import.c | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) (limited to 'g10/import.c') diff --git a/g10/import.c b/g10/import.c index 375bd03f8..b83f371ab 100644 --- a/g10/import.c +++ b/g10/import.c @@ -2067,8 +2067,11 @@ import_secret_one (ctrl_t ctrl, kbnode_t keyblock, { gpg_error_t err; - nr_prev = stats->secret_imported; - err = transfer_secret_keys (ctrl, stats, keyblock, batch, 0); + /* transfer_secret_keys collects subkey stats. */ + struct import_stats_s subkey_stats = {0}; + + err = transfer_secret_keys (ctrl, &subkey_stats, keyblock, + batch, 0); if (gpg_err_code (err) == GPG_ERR_NOT_PROCESSED) { /* TRANSLATORS: For smartcard, each private key on @@ -2091,8 +2094,14 @@ import_secret_one (ctrl_t ctrl, kbnode_t keyblock, if (!opt.quiet) log_info (_("key %s: secret key imported\n"), keystr_from_pk (pk)); - if (stats->secret_imported > nr_prev) - status |= 1; + if (subkey_stats.secret_imported) + { + status |= 1; + stats->secret_imported += 1; + } + if (subkey_stats.secret_dups) + stats->secret_dups += 1; + if (is_status_enabled ()) print_import_ok (pk, status); check_prefs (ctrl, node); -- cgit v1.2.3