aboutsummaryrefslogtreecommitdiffstats
path: root/kbx/keybox-init.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 /kbx/keybox-init.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 'kbx/keybox-init.c')
-rw-r--r--kbx/keybox-init.c44
1 files changed, 30 insertions, 14 deletions
diff --git a/kbx/keybox-init.c b/kbx/keybox-init.c
index 01d29f0f6..3b53cd5ec 100644
--- a/kbx/keybox-init.c
+++ b/kbx/keybox-init.c
@@ -286,27 +286,43 @@ keybox_lock (KEYBOX_HANDLE hd, int yes)
if (yes) /* Take the lock. */
{
- if (kb->is_locked)
- ;
- else if (dotlock_take (kb->lockhd, -1))
+ if (!kb->is_locked)
{
- err = gpg_error_from_syserror ();
- log_info ("can't lock '%s'\n", kb->fname );
+#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;
+ }
+#endif /*HAVE_W32_SYSTEM*/
+ if (dotlock_take (kb->lockhd, -1))
+ {
+ err = gpg_error_from_syserror ();
+ log_info ("can't lock '%s'\n", kb->fname );
+ }
+ else
+ kb->is_locked = 1;
}
- else
- kb->is_locked = 1;
}
else /* Release the lock. */
{
- if (!kb->is_locked)
- ;
- else if (dotlock_release (kb->lockhd))
+ if (kb->is_locked)
{
- err = gpg_error_from_syserror ();
- log_info ("can't unlock '%s'\n", kb->fname );
+ if (dotlock_release (kb->lockhd))
+ {
+ err = gpg_error_from_syserror ();
+ log_info ("can't unlock '%s'\n", kb->fname );
+ }
+ else
+ kb->is_locked = 0;
}
- else
- kb->is_locked = 0;
}
return err;