diff options
author | Werner Koch <[email protected]> | 2019-05-14 17:05:58 +0000 |
---|---|---|
committer | Werner Koch <[email protected]> | 2019-05-14 17:05:58 +0000 |
commit | 49b236af0ecbb6df67513feb4b63851f2e159ea2 (patch) | |
tree | 6235b36ce6d1955be5ebc3996b1633e0441f5227 /kbx/keybox-init.c | |
parent | sm: Change keydb code to use the keybox locking. (diff) | |
download | gnupg-49b236af0ecbb6df67513feb4b63851f2e159ea2.tar.gz gnupg-49b236af0ecbb6df67513feb4b63851f2e159ea2.zip |
kbx: Fix deadlock in gpgsm on Windows due to a sharing violation.
* kbx/keybox-init.c (keybox_lock) [W32]: Use _keybox_close_file
instead of fclose so that a close is done if the file is opened by
another handle.
* kbx/keybox-search.c (keybox_search): Remember the last offset and
use that in NEXT search mode if we had to re-open the file.
--
GnuPG-bug-id: 4505
Signed-off-by: Werner Koch <[email protected]>
Diffstat (limited to 'kbx/keybox-init.c')
-rw-r--r-- | kbx/keybox-init.c | 20 |
1 files changed, 8 insertions, 12 deletions
diff --git a/kbx/keybox-init.c b/kbx/keybox-init.c index 9a65c1345..2223f4d15 100644 --- a/kbx/keybox-init.c +++ b/kbx/keybox-init.c @@ -291,18 +291,14 @@ keybox_lock (KEYBOX_HANDLE hd, int yes, long timeout) if (!kb->is_locked) { #ifdef HAVE_W32_SYSTEM - /* Under Windows we need to close the file before we try - * to lock it. This is because another process might have - * taken the lock and is using keybox_file_rename to - * rename the base file. How if our dotlock_take below is - * waiting for the lock but we have the base file still - * open, keybox_file_rename will never succeed as we are - * in a deadlock. */ - if (hd->fp) - { - fclose (hd->fp); - hd->fp = NULL; - } + /* Under Windows we need to close the file before we try + * to lock it. This is because another process might have + * taken the lock and is using keybox_file_rename to + * rename the base file. Now if our dotlock_take below is + * waiting for the lock but we have the base file still + * open, keybox_file_rename will never succeed as we are + * in a deadlock. */ + _keybox_close_file (hd); #endif /*HAVE_W32_SYSTEM*/ if (dotlock_take (kb->lockhd, timeout)) { |