From a698adbb533fac12277aaf319ab08d0e7f027261 Mon Sep 17 00:00:00 2001 From: NIIBE Yutaka Date: Thu, 19 Sep 2024 13:44:56 +0900 Subject: [PATCH] kbx: Fix a race condition on DATABASE_HD. * kbx/backend-sqlite.c (create_or_open_database): Protect the access to DATABASE_HD. -- GnuPG-bug-id: 7294 Signed-off-by: NIIBE Yutaka --- kbx/backend-sqlite.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/kbx/backend-sqlite.c b/kbx/backend-sqlite.c index ec891da6d..50ab6f08b 100644 --- a/kbx/backend-sqlite.c +++ b/kbx/backend-sqlite.c @@ -568,11 +568,14 @@ create_or_open_database (ctrl_t ctrl, const char *filename) int dbversion; int setdbversion = 0; - if (database_hd) - return 0; /* Already initialized. */ - acquire_mutex (); + if (database_hd) + { + release_mutex (); + return 0; /* Already initialized. */ + } + /* To avoid races with other temporary instances of keyboxd trying * to create or update the database, we run the database with a lock * file held. */