mirror of
git://git.gnupg.org/gnupg.git
synced 2025-07-02 22:46:30 +02:00
gpg: Take care of keydb_new returning NULL.
* g10/keydb.c (keydb_new): Print an error message if needed. Also use
xtrycalloc because we return an error anyway.
* g10/delkey.c (do_delete_key): Handle error retruned by keydb_new.
* g10/export.c (do_export_stream): Ditto.
* g10/getkey.c (get_pubkey): Ditto.
(get_pubkey_fast): Ditto.
(get_pubkeyblock): Ditto.
(get_seckey): Ditto.
(key_byname): Ditto.
(get_pubkey_byfprint): Ditto.
(get_pubkey_byfprint_fast): Ditto.
(parse_def_secret_key): Ditto.
(have_secret_key_with_kid): Ditto.
* g10/import.c (import_one): Ditto.
(import_revoke_cert): Ditto.
* g10/keyedit.c (keyedit_quick_adduid): Ditto.
* g10/keygen.c (quick_generate_keypair): Ditto.
(do_generate_keypair): Ditto.
* g10/trustdb.c (validate_keys): Ditto.
* g10/keyserver.c (keyidlist): Ditto.
* g10/revoke.c (gen_desig_revoke): Ditto.
(gen_revoke): Ditto.
* g10/gpg.c (check_user_ids): Ditto.
(main): Do not print an error message for keydb_new error.
* g10/keylist.c (list_all): Use actual error code returned by
keydb_new.
* g10/t-keydb-get-keyblock.c (do_test): Abort on keydb_new error.
* g10/t-keydb.c (do_test): Ditto.
* g10/keyring.c (keyring_new): Actually return an error so that the
existing keydb_new error checking makes sense for a keyring resource.
(keyring_rebuild_cache): Take care of keyring_new returning an error.
--
Commit 04a6b903
changed keydb_new to return an error. However the
error was not checked at most places which we fix with this patch. To
make things easier keydb_new prints an error message itself.
Signed-off-by: Werner Koch <wk@gnupg.org>
This commit is contained in:
parent
9fcc047d92
commit
a28ac99efe
16 changed files with 155 additions and 37 deletions
27
g10/keydb.c
27
g10/keydb.c
|
@ -754,17 +754,26 @@ keydb_dump_stats (void)
|
|||
}
|
||||
|
||||
|
||||
/* Create a new database handle. A database handle is similar to a
|
||||
file handle: it contains a local file position. This is used when
|
||||
searching: subsequent searches resume where the previous search
|
||||
left off. To rewind the position, use keydb_search_reset(). This
|
||||
function returns NULL on error, sets ERRNO, and prints an error
|
||||
diagnostic. */
|
||||
KEYDB_HANDLE
|
||||
keydb_new (void)
|
||||
{
|
||||
KEYDB_HANDLE hd;
|
||||
int i, j;
|
||||
int die = 0;
|
||||
int reterrno;
|
||||
|
||||
if (DBG_CLOCK)
|
||||
log_clock ("keydb_new");
|
||||
|
||||
hd = xmalloc_clear (sizeof *hd);
|
||||
hd = xtrycalloc (1, sizeof *hd);
|
||||
if (!hd)
|
||||
goto leave;
|
||||
hd->found = -1;
|
||||
hd->saved_found = -1;
|
||||
hd->is_reset = 1;
|
||||
|
@ -781,7 +790,10 @@ keydb_new (void)
|
|||
hd->active[j].token = all_resources[i].token;
|
||||
hd->active[j].u.kr = keyring_new (all_resources[i].token);
|
||||
if (!hd->active[j].u.kr)
|
||||
die = 1;
|
||||
{
|
||||
reterrno = errno;
|
||||
die = 1;
|
||||
}
|
||||
j++;
|
||||
break;
|
||||
case KEYDB_RESOURCE_TYPE_KEYBOX:
|
||||
|
@ -789,7 +801,10 @@ keydb_new (void)
|
|||
hd->active[j].token = all_resources[i].token;
|
||||
hd->active[j].u.kb = keybox_new_openpgp (all_resources[i].token, 0);
|
||||
if (!hd->active[j].u.kb)
|
||||
die = 1;
|
||||
{
|
||||
reterrno = errno;
|
||||
die = 1;
|
||||
}
|
||||
j++;
|
||||
break;
|
||||
}
|
||||
|
@ -801,9 +816,15 @@ keydb_new (void)
|
|||
if (die)
|
||||
{
|
||||
keydb_release (hd);
|
||||
gpg_err_set_errno (reterrno);
|
||||
hd = NULL;
|
||||
}
|
||||
|
||||
leave:
|
||||
if (!hd)
|
||||
log_error (_("error opening key DB: %s\n"),
|
||||
gpg_strerror (gpg_error_from_syserror()));
|
||||
|
||||
return hd;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue