diff options
author | Werner Koch <wk@gnupg.org> | 2018-03-26 18:20:16 +0200 |
---|---|---|
committer | Werner Koch <wk@gnupg.org> | 2018-03-26 18:20:16 +0200 |
commit | eb68c2d3d1b03a18cd24406fa46d4c30cb13d9f7 (patch) | |
tree | 6889beaf65e47ea92f091e5919dc7b6369d0719c /g10/tdbio.c | |
parent | gpg: Pass CTRL arg to get_trusthashrec. (diff) | |
download | gnupg2-eb68c2d3d1b03a18cd24406fa46d4c30cb13d9f7.tar.xz gnupg2-eb68c2d3d1b03a18cd24406fa46d4c30cb13d9f7.zip |
gpg: Auto-fix a broken trustdb with just the version record.
* g10/tdbio.c (get_trusthashrec): Create hashtable on error.
GnuPG-bug-id: 3839
Signed-off-by: Werner Koch <wk@gnupg.org>
Diffstat (limited to 'g10/tdbio.c')
-rw-r--r-- | g10/tdbio.c | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/g10/tdbio.c b/g10/tdbio.c index 1e454869d..fed0cf5ab 100644 --- a/g10/tdbio.c +++ b/g10/tdbio.c @@ -990,6 +990,20 @@ get_trusthashrec (ctrl_t ctrl) log_fatal (_("%s: error reading version record: %s\n"), db_name, gpg_strerror (rc) ); + if (!vr.r.ver.trusthashtbl) + { + /* Oops: the trustdb is corrupt because the hashtable is + * always created along with the version record. However, + * if something went initially wrong it may happen that + * there is just the version record. We try to fix it here. + * If we can't do that we return 0 - this is the version + * record and thus the actual read will detect the mismatch + * and bail out. Note that create_hashtable updates VR. */ + take_write_lock (); + if (lseek (db_fd, 0, SEEK_END) == TRUST_RECORD_LEN) + create_hashtable (ctrl, &vr, 0); + release_write_lock (); + } trusthashtbl = vr.r.ver.trusthashtbl; } |