From b804378f183f7845dcdef8a953833f62684edfa7 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 2398aa77f..4c67c3ef7 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. */