[git] GnuPG - branch, master, updated. gnupg-2.1.15-371-g12834e8

by Justus Winter cvs at cvs.gnupg.org
Tue Nov 15 15:40:28 CET 2016


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, master has been updated
       via  12834e84aca9d74800245f0f2f2e6b5123e76173 (commit)
       via  d20107f6da094edd782947abb357abae5129a12c (commit)
       via  1d03cc77e1706f7da653153ad4b58c61e4fd2573 (commit)
       via  bd60742925414e0ef2a497df827c1913ea211a44 (commit)
      from  26c7c1d72c5f2acb3edb58d610c09a635c87bdbf (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 12834e84aca9d74800245f0f2f2e6b5123e76173
Author: Justus Winter <justus at g10code.com>
Date:   Tue Nov 15 15:33:09 2016 +0100

    g10: Optimize key iteration.
    
    * g10/getkey.c (get_best_pubkey_byname): Use the node returned by
    'getkey_next' instead of doing another lookup.
    
    Signed-off-by: Justus Winter <justus at g10code.com>

diff --git a/g10/getkey.c b/g10/getkey.c
index 7bc5c88..5792302 100644
--- a/g10/getkey.c
+++ b/g10/getkey.c
@@ -1593,9 +1593,9 @@ get_best_pubkey_byname (ctrl_t ctrl, GETKEY_CTX *retctx, PKT_public_key *pk,
     {
       /* Rank results and return only the most relevant key.  */
       struct pubkey_cmp_cookie best = { 0 }, new;
-      while (getkey_next (ctx, &new.key, NULL) == 0)
+      KBNODE new_keyblock;
+      while (getkey_next (ctx, &new.key, &new_keyblock) == 0)
         {
-          KBNODE new_keyblock = get_pubkeyblock (pk_keyid (&new.key));
           int diff = pubkey_cmp (ctrl, name, &best, &new, new_keyblock);
           release_kbnode (new_keyblock);
           if (diff < 0)

commit d20107f6da094edd782947abb357abae5129a12c
Author: Justus Winter <justus at g10code.com>
Date:   Tue Nov 15 15:11:39 2016 +0100

    g10: Fix memory leak.
    
    * g10/getkey.c (finish_lookup): Clarify that we do not return a
    reference.
    (lookup): Clarify the relation between RET_KEYBLOCK and RET_FOUND_KEY.
    Check arguments.  Actually release the node if it is not returned.
    
    Signed-off-by: Justus Winter <justus at g10code.com>

diff --git a/g10/getkey.c b/g10/getkey.c
index 6232363..7bc5c88 100644
--- a/g10/getkey.c
+++ b/g10/getkey.c
@@ -3341,6 +3341,9 @@ merge_selfsigs (KBNODE keyblock)
  * in CTX.  If so, return the node of an appropriate key or subkey.
  * Otherwise, return NULL if there was no appropriate key.
  *
+ * Note that we do not return a reference, i.e. the result must not be
+ * freed using 'release_kbnode'.
+ *
  * In case the primary key is not required, select a suitable subkey.
  * We need the primary key if PUBKEY_USAGE_CERT is set in REQ_USAGE or
  * we are in PGP6 or PGP7 mode and PUBKEY_USAGE_SIG is set in
@@ -3660,7 +3663,12 @@ print_status_key_considered (kbnode_t keyblock, unsigned int flags)
    all of the self-signed data into the keys, subkeys and user id
    packets (see the merge_selfsigs for details).
 
-   On success the key's keyblock is stored at *RET_KEYBLOCK.  */
+   On success the key's keyblock is stored at *RET_KEYBLOCK, and the
+   specific subkey is stored at *RET_FOUND_KEY.  Note that we do not
+   return a reference in *RET_FOUND_KEY, i.e. the result must not be
+   freed using 'release_kbnode', and it is only valid until
+   *RET_KEYBLOCK is deallocated.  Therefore, if RET_FOUND_KEY is not
+   NULL, then RET_KEYBLOCK must not be NULL.  */
 static int
 lookup (getkey_ctx_t ctx, kbnode_t *ret_keyblock, kbnode_t *ret_found_key,
 	int want_secret)
@@ -3671,6 +3679,7 @@ lookup (getkey_ctx_t ctx, kbnode_t *ret_keyblock, kbnode_t *ret_found_key,
   KBNODE found_key = NULL;
   unsigned int infoflags;
 
+  log_assert (ret_found_key == NULL || ret_keyblock != NULL);
   if (ret_keyblock)
     *ret_keyblock = NULL;
 
@@ -3732,8 +3741,10 @@ lookup (getkey_ctx_t ctx, kbnode_t *ret_keyblock, kbnode_t *ret_found_key,
   if (!rc)
     {
       if (ret_keyblock)
-        *ret_keyblock = keyblock; /* Return the keyblock.  */
-      keyblock = NULL;
+        {
+          *ret_keyblock = keyblock; /* Return the keyblock.  */
+          keyblock = NULL;
+        }
     }
   else if (gpg_err_code (rc) == GPG_ERR_NOT_FOUND && no_suitable_key)
     rc = want_secret? GPG_ERR_UNUSABLE_SECKEY : GPG_ERR_UNUSABLE_PUBKEY;

commit 1d03cc77e1706f7da653153ad4b58c61e4fd2573
Author: Justus Winter <justus at g10code.com>
Date:   Tue Nov 15 15:08:54 2016 +0100

    g10: Fix iteration over getkey results.
    
    * g10/getkey.c (getkey_next): Fix invocation of 'lookup'.  If we want
    to use RET_FOUND_KEY, RET_KEYBLOCK must be valid.
    
    Fixes-commit: 8ea72a776a88f3c851e812d258355be80caa1bc1
    Signed-off-by: Justus Winter <justus at g10code.com>

diff --git a/g10/getkey.c b/g10/getkey.c
index bf197b2..6232363 100644
--- a/g10/getkey.c
+++ b/g10/getkey.c
@@ -2167,6 +2167,7 @@ gpg_error_t
 getkey_next (getkey_ctx_t ctx, PKT_public_key *pk, kbnode_t *ret_keyblock)
 {
   int rc; /* Fixme:  Make sure this is proper gpg_error */
+  KBNODE keyblock = NULL;
   KBNODE found_key = NULL;
 
   /* We need to disable the caching so that for an exact key search we
@@ -2175,11 +2176,18 @@ getkey_next (getkey_ctx_t ctx, PKT_public_key *pk, kbnode_t *ret_keyblock)
      used without respecting the current file pointer!  */
   keydb_disable_caching (ctx->kr_handle);
 
+  /* FOUND_KEY is only valid as long as RET_KEYBLOCK is.  If the
+   * caller wants PK, but not RET_KEYBLOCK, we need hand in our own
+   * keyblock.  */
+  if (pk && ret_keyblock == NULL)
+      ret_keyblock = &keyblock;
+
   rc = lookup (ctx, ret_keyblock, &found_key, ctx->want_secret);
   if (!rc && pk)
     {
       log_assert (found_key);
       pk_from_block (pk, NULL, found_key);
+      release_kbnode (keyblock);
     }
 
   return rc;

commit bd60742925414e0ef2a497df827c1913ea211a44
Author: Justus Winter <justus at g10code.com>
Date:   Tue Nov 15 15:06:28 2016 +0100

    g10: Fix use-after-free.
    
    * g10/getkey.c (pubkey_cmp): Make a copy of the user id.
    (get_best_pubkey_byname): Free the user ids.
    
    Signed-off-by: Justus Winter <justus at g10code.com>

diff --git a/g10/getkey.c b/g10/getkey.c
index 59625e7..bf197b2 100644
--- a/g10/getkey.c
+++ b/g10/getkey.c
@@ -1541,7 +1541,7 @@ pubkey_cmp (ctrl_t ctrl, const char *name, struct pubkey_cmp_cookie *old,
       if (! match)
         continue;
 
-      new->uid = uid;
+      new->uid = scopy_user_id (uid);
       new->validity =
         get_validity (ctrl, &new->key, uid, NULL, 0) & TRUST_MASK;
       new->valid = 1;
@@ -1602,21 +1602,29 @@ get_best_pubkey_byname (ctrl_t ctrl, GETKEY_CTX *retctx, PKT_public_key *pk,
             {
               /* New key is better.  */
               release_public_key_parts (&best.key);
+              if (best.uid)
+                free_user_id (best.uid);
               best = new;
             }
           else if (diff > 0)
             {
               /* Old key is better.  */
               release_public_key_parts (&new.key);
+              if (new.uid)
+                free_user_id (new.uid);
             }
           else
             {
               /* A tie.  Keep the old key.  */
               release_public_key_parts (&new.key);
+              if (new.uid)
+                free_user_id (new.uid);
             }
         }
       getkey_end (ctx);
       ctx = NULL;
+      if (best.uid)
+        free_user_id (best.uid);
 
       if (best.valid)
         {

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

Summary of changes:
 g10/getkey.c | 39 +++++++++++++++++++++++++++++++++------
 1 file changed, 33 insertions(+), 6 deletions(-)


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




More information about the Gnupg-commits mailing list