[git] GnuPG - branch, STABLE-BRANCH-2-2, updated. gnupg-2.2.5-27-g456a3a8
by Werner Koch
cvs at cvs.gnupg.org
Mon Mar 26 17:03:55 CEST 2018
This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "The GNU Privacy Guard".
The branch, STABLE-BRANCH-2-2 has been updated
via 456a3a8e93ea14f821e0e98fb515f284ece98685 (commit)
via 5f00531463ebc0e606c502696962426007545bb7 (commit)
from 137644c9cb58deaaba6850f2763d9c5f9241cb0b (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commit 456a3a8e93ea14f821e0e98fb515f284ece98685
Author: Werner Koch <wk at gnupg.org>
Date: Mon Mar 26 16:57:04 2018 +0200
gpg: Fix trustdb updates without lock held.
* g10/tdbio.c (is_locked): Turn into a counter.
(take_write_lock, release_write_lock): Implement recursive locks.
--
On trustdb creation we have this call sequence:
init_trustdb -> takes lock
tdbio_set_dbname
create_version_record
tdbio_write_record
put_record_into_cache -> takes lock
put_record_into_cache -> releases lock
init_trustdb -> releases lock
The second take lock does noting but the first release lock has
already released the lock and the second release lock is a thus a NOP.
This is likely the cause for the corrupted trustdb as reported in
GnuPG-bug-id: 3839
Signed-off-by: Werner Koch <wk at gnupg.org>
diff --git a/g10/tdbio.c b/g10/tdbio.c
index fb3cf15..4940c5c 100644
--- a/g10/tdbio.c
+++ b/g10/tdbio.c
@@ -105,10 +105,11 @@ struct cmp_xdir_struct
/* The name of the trustdb file. */
static char *db_name;
-/* The handle for locking the trustdb file and a flag to record
- whether a lock has been taken. */
+/* The handle for locking the trustdb file and a counter to record how
+ * often this lock has been taken. That counter is required becuase
+ * dotlock does not implemen recursive locks. */
static dotlock_t lockhandle;
-static int is_locked;
+static unsigned int is_locked;
/* The file descriptor of the trustdb. */
static int db_fd = -1;
@@ -135,6 +136,8 @@ static void create_hashtable (ctrl_t ctrl, TRUSTREC *vr, int type);
static int
take_write_lock (void)
{
+ int rc;
+
if (!lockhandle)
lockhandle = dotlock_create (db_name, 0);
if (!lockhandle)
@@ -144,12 +147,16 @@ take_write_lock (void)
{
if (dotlock_take (lockhandle, -1) )
log_fatal ( _("can't lock '%s'\n"), db_name );
- else
- is_locked = 1;
- return 0;
+ rc = 0;
}
else
- return 1;
+ rc = 1;
+
+ if (opt.lock_once)
+ is_locked = 1;
+ else
+ is_locked++;
+ return rc;
}
@@ -160,10 +167,22 @@ take_write_lock (void)
static void
release_write_lock (void)
{
- if (!opt.lock_once)
- if (!dotlock_release (lockhandle))
- is_locked = 0;
+ if (opt.lock_once)
+ return; /* Don't care; here IS_LOCKED is fixed to 1. */
+
+ if (!is_locked)
+ {
+ log_error ("Ooops, tdbio:release_write_lock with no lock held\n");
+ return;
+ }
+ if (--is_locked)
+ return;
+
+ if (dotlock_release (lockhandle))
+ log_error ("Oops, tdbio:release_write_locked failed\n");
}
+
+
/*************************************
************* record cache **********
commit 5f00531463ebc0e606c502696962426007545bb7
Author: Werner Koch <wk at gnupg.org>
Date: Mon Mar 26 16:26:46 2018 +0200
gpg: Disable unused code parts in tdbio.c
* g10/tdbio.c (in_transaction): Comment this var.
(put_record_into_cache): Comment the transaction code.
(tdbio_sync): Ditto
Signed-off-by: Werner Koch <wk at gnupg.org>
diff --git a/g10/tdbio.c b/g10/tdbio.c
index 7572b9a..fb3cf15 100644
--- a/g10/tdbio.c
+++ b/g10/tdbio.c
@@ -114,7 +114,7 @@ static int is_locked;
static int db_fd = -1;
/* A flag indicating that a transaction is active. */
-static int in_transaction;
+/* static int in_transaction; Not yet used. */
@@ -125,7 +125,7 @@ static void create_hashtable (ctrl_t ctrl, TRUSTREC *vr, int type);
/*
* Take a lock on the trustdb file name. I a lock file can't be
- * created the function terminates the process. Excvept for a
+ * created the function terminates the process. Except for a
* different return code the function does nothing if the lock has
* already been taken.
*
@@ -329,6 +329,7 @@ put_record_into_cache (ulong recno, const char *data)
}
/* No clean entries: We have to flush some dirty entries. */
+#if 0 /* Transactions are not yet used. */
if (in_transaction)
{
/* But we can't do this while in a transaction. Thus we
@@ -352,6 +353,7 @@ put_record_into_cache (ulong recno, const char *data)
log_info (_("trustdb transaction too large\n"));
return GPG_ERR_RESOURCE_LIMIT;
}
+#endif
if (dirty_count)
{
@@ -418,8 +420,10 @@ tdbio_sync()
if( db_fd == -1 )
open_db();
+#if 0 /* Transactions are not yet used. */
if( in_transaction )
log_bug("tdbio: syncing while in transaction\n");
+#endif
if( !cache_is_dirty )
return 0;
@@ -560,7 +564,7 @@ tdbio_update_version_record (ctrl_t ctrl)
/*
* Create and write the trustdb version record.
- *
+ * This is called with the writelock activ.
* Returns: 0 on success or an error code.
*/
static int
-----------------------------------------------------------------------
Summary of changes:
g10/tdbio.c | 49 ++++++++++++++++++++++++++++++++++++-------------
1 file changed, 36 insertions(+), 13 deletions(-)
hooks/post-receive
--
The GNU Privacy Guard
http://git.gnupg.org
More information about the Gnupg-commits
mailing list