gpg: Keep a lock during the read-update/insert cycle in import.
authorWerner Koch <wk@gnupg.org>
Wed, 18 Oct 2017 16:28:52 +0000 (18:28 +0200)
committerWerner Koch <wk@gnupg.org>
Thu, 19 Oct 2017 13:02:28 +0000 (15:02 +0200)
commit7c73db3d31c6457dfbdc82a8dc89951c023f0603
treec9a14778d15e4cb06b617fe772f1225c12460183
parent8448347b5bdee56e6f9938a93ea92fe4d3c8800c
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
g10/getkey.c
g10/keydb.c
g10/keydb.h