aboutsummaryrefslogtreecommitdiffstats
path: root/g10/getkey.c
diff options
context:
space:
mode:
authorWerner Koch <[email protected]>2017-10-18 16:28:52 +0000
committerWerner Koch <[email protected]>2017-10-18 16:28:52 +0000
commit645f30ad310a518a863eb7bd3e11251a7e7f2eca (patch)
tree5e40963b60cf50eb7169d09624ae4be4401a2035 /g10/getkey.c
parentgpg: Improve keydb handling in the main import function. (diff)
downloadgnupg-645f30ad310a518a863eb7bd3e11251a7e7f2eca.tar.gz
gnupg-645f30ad310a518a863eb7bd3e11251a7e7f2eca.zip
gpg: Keep a lock during the read-update/insert cycle in import.
* g10/keydb.c (keydb_handle): New field 'keep_lock'. (keydb_release): Clear that flag. (keydb_lock): New function. (unlock_all): Skip if KEEP_LOCK is set. * g10/getkey.c (get_keyblock_byfprint_fast): Call keep_lock if requested. -- That change is straightforward. It helps to avoid the race condition that another gpg process inserts a key while the first process is between the search and the insert. A similar change is due for gpgsm. Note that the key edit operations may still suffer from a race. GnuPG-bug-id: 3446
Diffstat (limited to 'g10/getkey.c')
-rw-r--r--g10/getkey.c15
1 files changed, 13 insertions, 2 deletions
diff --git a/g10/getkey.c b/g10/getkey.c
index 6d18d29a5..7061f51eb 100644
--- a/g10/getkey.c
+++ b/g10/getkey.c
@@ -1877,14 +1877,25 @@ get_keyblock_byfprint_fast (kbnode_t *r_keyblock, KEYDB_HANDLE *r_hd,
hd = keydb_new ();
if (!hd)
return gpg_error_from_syserror ();
- if (r_hd)
- *r_hd = hd;
if (lock)
{
+ err = keydb_lock (hd);
+ if (err)
+ {
+ /* If locking did not work, we better don't return a handle
+ * at all - there was a reason that locking has been
+ * requested. */
+ keydb_release (hd);
+ return err;
+ }
keydb_disable_caching (hd);
}
+ /* Fo all other errors we return the handle. */
+ if (r_hd)
+ *r_hd = hd;
+
err = keydb_search_fpr (hd, fprbuf);
if (gpg_err_code (err) == GPG_ERR_NOT_FOUND)
{