gpg: Don't forget to free some memory.
[gnupg.git] / g10 / keyring.c
index 6060f08..81d2174 100644 (file)
@@ -1,5 +1,6 @@
 /* keyring.c - keyring file handling
- * Copyright (C) 2001, 2004, 2009, 2010 Free Software Foundation, Inc.
+ * Copyright (C) 1998-2010 Free Software Foundation, Inc.
+ * Copyright (C) 1997-2015 Werner Koch
  *
  * This file is part of GnuPG.
  *
@@ -83,7 +84,7 @@ struct keyring_handle
     size_t pk_no;
     size_t uid_no;
     unsigned int n_packets; /*used for delete and update*/
-  } found;
+  } found, saved_found;
   struct {
     char *name;
     char *pattern;
@@ -279,6 +280,25 @@ keyring_release (KEYRING_HANDLE hd)
 }
 
 
+/* Save the current found state in HD for later retrieval by
+   keybox_pop_found_state.  Only one state may be saved.  */
+void
+keyring_push_found_state (KEYRING_HANDLE hd)
+{
+  hd->saved_found = hd->found;
+  hd->found.kr = NULL;
+}
+
+
+/* Restore the saved found state in HD.  */
+void
+keyring_pop_found_state (KEYRING_HANDLE hd)
+{
+  hd->found = hd->saved_found;
+  hd->saved_found.kr = NULL;
+}
+
+
 const char *
 keyring_get_resource_name (KEYRING_HANDLE hd)
 {
@@ -406,12 +426,31 @@ keyring_get_keyblock (KEYRING_HANDLE hd, KBNODE *ret_kb)
             rc = GPG_ERR_INV_KEYRING;
             break;
         }
-       if (pkt->pkttype == PKT_COMPRESSED) {
-           log_error ("skipped compressed packet in keyring\n");
+
+        /* Filter allowed packets.  */
+        switch (pkt->pkttype)
+          {
+          case PKT_PUBLIC_KEY:
+          case PKT_PUBLIC_SUBKEY:
+          case PKT_SECRET_KEY:
+          case PKT_SECRET_SUBKEY:
+          case PKT_USER_ID:
+          case PKT_ATTRIBUTE:
+          case PKT_SIGNATURE:
+            break; /* Allowed per RFC.  */
+          case PKT_RING_TRUST:
+          case PKT_OLD_COMMENT:
+          case PKT_COMMENT:
+          case PKT_GPG_CONTROL:
+            break; /* Allowed by us.  */
+
+          default:
+           log_error ("skipped packet of type %d in keyring\n",
+                       (int)pkt->pkttype);
            free_packet(pkt);
            init_packet(pkt);
            continue;
-        }
+          }
 
         if (in_cert && (pkt->pkttype == PKT_PUBLIC_KEY
                         || pkt->pkttype == PKT_SECRET_KEY)) {
@@ -478,7 +517,7 @@ keyring_get_keyblock (KEYRING_HANDLE hd, KBNODE *ret_kb)
     if (rc || !ret_kb)
        release_kbnode (keyblock);
     else {
-        /*(duplicated form the loop body)*/
+        /*(duplicated from the loop body)*/
         if ( pkt && pkt->pkttype == PKT_RING_TRUST
              && lastnode
              && lastnode->pkt->pkttype == PKT_SIGNATURE
@@ -1109,7 +1148,7 @@ keyring_search (KEYRING_HANDLE hd, KEYDB_SEARCH_DESC *desc,
       for (n=any_skip?0:ndesc; n < ndesc; n++)
         {
           if (desc[n].skipfnc
-              && desc[n].skipfnc (desc[n].skipfncvalue, aki, uid))
+              && desc[n].skipfnc (desc[n].skipfncvalue, aki, uid_no))
             break;
         }
       if (n == ndesc)