aboutsummaryrefslogtreecommitdiffstats
path: root/g10/keyring.c
diff options
context:
space:
mode:
authorWerner Koch <[email protected]>2016-01-14 19:45:33 +0000
committerWerner Koch <[email protected]>2016-01-14 19:45:33 +0000
commit663c5d129a8f400cc6eb8ab7b91772d6e578152d (patch)
tree43026236515008a27c4ec854c1630050a0d15e43 /g10/keyring.c
parentgpg: Detect race between pubring.gpg and pubring.kbx use. (diff)
downloadgnupg-663c5d129a8f400cc6eb8ab7b91772d6e578152d.tar.gz
gnupg-663c5d129a8f400cc6eb8ab7b91772d6e578152d.zip
w32: Fix deadlock introduced by keybox_file_rename.
* g10/keyring.c (keyring_lock) [W32]: Flush the close cache before locking. * kbx/keybox-init.c (keybox_lock) [W32]: Close the file before locking. Signed-off-by: Werner Koch <[email protected]>
Diffstat (limited to 'g10/keyring.c')
-rw-r--r--g10/keyring.c21
1 files changed, 17 insertions, 4 deletions
diff --git a/g10/keyring.c b/g10/keyring.c
index 7ae50a392..ca9a69874 100644
--- a/g10/keyring.c
+++ b/g10/keyring.c
@@ -328,8 +328,20 @@ keyring_lock (KEYRING_HANDLE hd, int yes)
if (!keyring_is_writable(kr))
continue;
if (kr->is_locked)
- ;
- else if (dotlock_take (kr->lockhd, -1) ) {
+ continue;
+
+#ifdef HAVE_W32_SYSTEM
+ /* Under Windows we need to CloseHandle 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. */
+ iobuf_ioctl (NULL, IOBUF_IOCTL_INVALIDATE_CACHE, 0,
+ (char*)kr->fname);
+#endif /*HAVE_W32_SYSTEM*/
+ if (dotlock_take (kr->lockhd, -1) ) {
log_info ("can't lock '%s'\n", kr->fname );
rc = GPG_ERR_GENERAL;
}
@@ -343,8 +355,9 @@ keyring_lock (KEYRING_HANDLE hd, int yes)
if (!keyring_is_writable(kr))
continue;
if (!kr->is_locked)
- ;
- else if (dotlock_release (kr->lockhd))
+ continue;
+
+ if (dotlock_release (kr->lockhd))
log_info ("can't unlock '%s'\n", kr->fname );
else
kr->is_locked = 0;