gpg: Fix trustdb updates without lock held.
authorWerner Koch <wk@gnupg.org>
Mon, 26 Mar 2018 14:57:04 +0000 (16:57 +0200)
committerWerner Koch <wk@gnupg.org>
Mon, 26 Mar 2018 14:57:04 +0000 (16:57 +0200)
commit456a3a8e93ea14f821e0e98fb515f284ece98685
treefcef497177f57770b933ddbd7e06182a11baa2ba
parent5f00531463ebc0e606c502696962426007545bb7
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@gnupg.org>
g10/tdbio.c