[git] GnuPG - branch, STABLE-BRANCH-2-2, updated. gnupg-2.2.5-30-geb68c2d

by Werner Koch cvs at cvs.gnupg.org
Mon Mar 26 18:28:35 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  eb68c2d3d1b03a18cd24406fa46d4c30cb13d9f7 (commit)
       via  a750ebebf35a392f1c72d6aee5618df0d9f25ff7 (commit)
       via  403aa70c52e56614d65490dea9344113f9cf3d29 (commit)
      from  456a3a8e93ea14f821e0e98fb515f284ece98685 (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 eb68c2d3d1b03a18cd24406fa46d4c30cb13d9f7
Author: Werner Koch <wk at gnupg.org>
Date:   Mon Mar 26 18:20:16 2018 +0200

    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 at gnupg.org>

diff --git a/g10/tdbio.c b/g10/tdbio.c
index 1e45486..fed0cf5 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;
     }
 

commit a750ebebf35a392f1c72d6aee5618df0d9f25ff7
Author: Werner Koch <wk at gnupg.org>
Date:   Mon Mar 26 18:06:43 2018 +0200

    gpg: Pass CTRL arg to get_trusthashrec.
    
    * g10/tdbio.c (get_trusthashrec): Add arg CTRL.
    (tdbio_search_trust_byfpr): Ditto.
    (tdbio_search_trust_bypk): Ditto.
    
    Signed-off-by: Werner Koch <wk at gnupg.org>

diff --git a/g10/tdbdump.c b/g10/tdbdump.c
index 5ea903f..2c6f5c2 100644
--- a/g10/tdbdump.c
+++ b/g10/tdbdump.c
@@ -189,7 +189,7 @@ import_ownertrust (ctrl_t ctrl, const char *fname )
 	while (fprlen < 20)
 	    fpr[fprlen++] = 0;
 
-	rc = tdbio_search_trust_byfpr (fpr, &rec);
+	rc = tdbio_search_trust_byfpr (ctrl, fpr, &rec);
 	if( !rc ) { /* found: update */
 	    if (rec.r.trust.ownertrust != otrust)
               {
diff --git a/g10/tdbio.c b/g10/tdbio.c
index 7314143..1e45486 100644
--- a/g10/tdbio.c
+++ b/g10/tdbio.c
@@ -974,10 +974,12 @@ tdbio_write_nextcheck (ctrl_t ctrl, ulong stamp)
  * Return: record number
  */
 static ulong
-get_trusthashrec(void)
+get_trusthashrec (ctrl_t ctrl)
 {
   static ulong trusthashtbl; /* Record number of the trust hashtable.  */
 
+  (void)ctrl;
+
   if (!trusthashtbl)
     {
       TRUSTREC vr;
@@ -1388,7 +1390,7 @@ lookup_hashtable (ulong table, const byte *key, size_t keylen,
 static int
 update_trusthashtbl (ctrl_t ctrl, TRUSTREC *tr)
 {
-  return upd_hashtable (ctrl, get_trusthashrec (),
+  return upd_hashtable (ctrl, get_trusthashrec (ctrl),
                         tr->r.trust.fingerprint, 20, tr->recnum);
 }
 
@@ -1730,7 +1732,7 @@ tdbio_delete_record (ctrl_t ctrl, ulong recnum)
     ;
   else if (rec.rectype == RECTYPE_TRUST)
     {
-      rc = drop_from_hashtable (ctrl, get_trusthashrec(),
+      rc = drop_from_hashtable (ctrl, get_trusthashrec (ctrl),
                                 rec.r.trust.fingerprint, 20, rec.recnum);
     }
 
@@ -1852,12 +1854,12 @@ cmp_trec_fpr ( const void *fpr, const TRUSTREC *rec )
  * Return: 0 if found, GPG_ERR_NOT_FOUND, or another error code.
  */
 gpg_error_t
-tdbio_search_trust_byfpr (const byte *fingerprint, TRUSTREC *rec)
+tdbio_search_trust_byfpr (ctrl_t ctrl, const byte *fingerprint, TRUSTREC *rec)
 {
   int rc;
 
   /* Locate the trust record using the hash table */
-  rc = lookup_hashtable (get_trusthashrec(), fingerprint, 20,
+  rc = lookup_hashtable (get_trusthashrec (ctrl), fingerprint, 20,
                          cmp_trec_fpr, fingerprint, rec );
   return rc;
 }
@@ -1870,7 +1872,7 @@ tdbio_search_trust_byfpr (const byte *fingerprint, TRUSTREC *rec)
  * Return: 0 if found, GPG_ERR_NOT_FOUND, or another error code.
  */
 gpg_error_t
-tdbio_search_trust_bypk (PKT_public_key *pk, TRUSTREC *rec)
+tdbio_search_trust_bypk (ctrl_t ctrl, PKT_public_key *pk, TRUSTREC *rec)
 {
   byte fingerprint[MAX_FINGERPRINT_LEN];
   size_t fingerlen;
@@ -1878,7 +1880,7 @@ tdbio_search_trust_bypk (PKT_public_key *pk, TRUSTREC *rec)
   fingerprint_from_pk( pk, fingerprint, &fingerlen );
   for (; fingerlen < 20; fingerlen++)
     fingerprint[fingerlen] = 0;
-  return tdbio_search_trust_byfpr (fingerprint, rec);
+  return tdbio_search_trust_byfpr (ctrl, fingerprint, rec);
 }
 
 
diff --git a/g10/tdbio.h b/g10/tdbio.h
index beaa308..267a3797 100644
--- a/g10/tdbio.h
+++ b/g10/tdbio.h
@@ -110,8 +110,10 @@ int tdbio_end_transaction(void);
 int tdbio_cancel_transaction(void);
 int tdbio_delete_record (ctrl_t ctrl, ulong recnum);
 ulong tdbio_new_recnum (ctrl_t ctrl);
-gpg_error_t tdbio_search_trust_byfpr (const byte *fingerprint, TRUSTREC *rec);
-gpg_error_t tdbio_search_trust_bypk (PKT_public_key *pk, TRUSTREC *rec);
+gpg_error_t tdbio_search_trust_byfpr (ctrl_t ctrl, const byte *fingerprint,
+                                      TRUSTREC *rec);
+gpg_error_t tdbio_search_trust_bypk (ctrl_t ctrl, PKT_public_key *pk,
+                                     TRUSTREC *rec);
 
 void tdbio_how_to_fix (void);
 void tdbio_invalid(void);
diff --git a/g10/trustdb.c b/g10/trustdb.c
index 0a98c12..2c2d239 100644
--- a/g10/trustdb.c
+++ b/g10/trustdb.c
@@ -649,7 +649,7 @@ read_trust_record (ctrl_t ctrl, PKT_public_key *pk, TRUSTREC *rec)
   int rc;
 
   init_trustdb (ctrl, 0);
-  rc = tdbio_search_trust_bypk (pk, rec);
+  rc = tdbio_search_trust_bypk (ctrl, pk, rec);
   if (rc)
     {
       if (gpg_err_code (rc) != GPG_ERR_NOT_FOUND)

commit 403aa70c52e56614d65490dea9344113f9cf3d29
Author: Werner Koch <wk at gnupg.org>
Date:   Mon Mar 26 17:43:40 2018 +0200

    gpg: Return better error codes in case of a too short trustdb.
    
    * g10/tdbio.c (tdbio_read_record): Return GPG_ERR_EOF.
    (tdbio_new_recnum): Never return on error.
    (lookup_hashtable): Print a more descriptive error in case of !TABLE.
    --
    
    Also: tdbio_new_recnum had a bug in that it returned an error code and
    not a record number in the error case.  The function is expected to
    always return a valid new record number.
    
    Signed-off-by: Werner Koch <wk at gnupg.org>

diff --git a/g10/tdbio.c b/g10/tdbio.c
index 4940c5c..7314143 100644
--- a/g10/tdbio.c
+++ b/g10/tdbio.c
@@ -1292,6 +1292,13 @@ lookup_hashtable (ulong table, const byte *key, size_t keylen,
   int msb;
   int level = 0;
 
+  if (!table)
+    {
+      rc = gpg_error (GPG_ERR_INV_RECORD);
+      log_error("lookup_hashtable failed: %s\n", "request for record 0");
+      return rc;
+    }
+
   hashrec = table;
  next_level:
   msb = key[level];
@@ -1464,7 +1471,7 @@ tdbio_dump_record (TRUSTREC *rec, estream_t fp)
  * EXPECTED is not 0 reading any other record type will return an
  * error.
  *
- * Return: 0 on success, -1 on EOF, or an error code.
+ * Return: 0 on success or an error code.
  */
 int
 tdbio_read_record (ulong recnum, TRUSTREC *rec, int expected)
@@ -1489,7 +1496,7 @@ tdbio_read_record (ulong recnum, TRUSTREC *rec, int expected)
       n = read (db_fd, readbuf, TRUST_RECORD_LEN);
       if (!n)
         {
-          return -1; /* eof */
+          return gpg_error (GPG_ERR_EOF);
 	}
       else if (n != TRUST_RECORD_LEN)
         {
@@ -1769,20 +1776,14 @@ tdbio_new_recnum (ctrl_t ctrl)
       recnum = vr.r.ver.firstfree;
       rc = tdbio_read_record (recnum, &rec, RECTYPE_FREE);
       if (rc)
-        {
-          log_error (_("%s: error reading free record: %s\n"),
-                     db_name,  gpg_strerror (rc));
-          return rc;
-	}
+        log_fatal (_("%s: error reading free record: %s\n"),
+                   db_name, gpg_strerror (rc));
       /* Update dir record.  */
       vr.r.ver.firstfree = rec.r.free.next;
       rc = tdbio_write_record (ctrl, &vr);
       if (rc)
-        {
-          log_error (_("%s: error writing dir record: %s\n"),
-                     db_name, gpg_strerror (rc));
-          return rc;
-	}
+        log_fatal (_("%s: error writing dir record: %s\n"),
+                   db_name, gpg_strerror (rc));
       /* Zero out the new record.  */
       memset (&rec, 0, sizeof rec);
       rec.rectype = 0; /* Mark as unused record (actually already done
@@ -1799,7 +1800,7 @@ tdbio_new_recnum (ctrl_t ctrl)
       if (offset == (off_t)(-1))
         log_fatal ("trustdb: lseek to end failed: %s\n", strerror (errno));
       recnum = offset / TRUST_RECORD_LEN;
-      log_assert (recnum); /* this is will never be the first record */
+      log_assert (recnum); /* This will never be the first record */
       /* We must write a record, so that the next call to this
        * function returns another recnum.  */
       memset (&rec, 0, sizeof rec);
@@ -1821,13 +1822,13 @@ tdbio_new_recnum (ctrl_t ctrl)
             {
               rc = gpg_error_from_syserror ();
               log_error (_("trustdb rec %lu: write failed (n=%d): %s\n"),
-                         recnum, n, strerror (errno));
+                         recnum, n, gpg_strerror (rc));
 	    }
 	}
 
       if (rc)
         log_fatal (_("%s: failed to append a record: %s\n"),
-                   db_name,	gpg_strerror (rc));
+                   db_name, gpg_strerror (rc));
     }
 
   return recnum ;

-----------------------------------------------------------------------

Summary of changes:
 g10/tdbdump.c |  2 +-
 g10/tdbio.c   | 61 ++++++++++++++++++++++++++++++++++++++---------------------
 g10/tdbio.h   |  6 ++++--
 g10/trustdb.c |  2 +-
 4 files changed, 45 insertions(+), 26 deletions(-)


hooks/post-receive
-- 
The GNU Privacy Guard
http://git.gnupg.org




More information about the Gnupg-commits mailing list