Blame SOURCES/gnupg-2.2.21-coverity.patch

b5a5d8
diff -up gnupg-2.2.21/common/server-help.c.coverity gnupg-2.2.21/common/server-help.c
b5a5d8
--- gnupg-2.2.21/common/server-help.c.coverity 2019-02-11 10:59:34.000000000 +0100
b5a5d8
+++ gnupg-2.2.21/common/server-help.c  2020-07-20 17:09:57.416148768 +0200
b5a5d8
@@ -156,7 +156,7 @@ get_option_value (char *line, const char
b5a5d8
   *pend = 0;
b5a5d8
   *r_value = xtrystrdup (p);
b5a5d8
   *pend = c;
b5a5d8
-  if (!p)
b5a5d8
+  if (!*r_value)
b5a5d8
     return my_error_from_syserror ();
b5a5d8
   return 0;
b5a5d8
 }
b5a5d8
b5a5d8
b5a5d8
From 912e77f07d8a42d7ad001eb3df76f6932ccfa857 Mon Sep 17 00:00:00 2001
b5a5d8
From: Jakub Jelen <jjelen@redhat.com>
b5a5d8
Date: Wed, 7 Apr 2021 17:37:51 +0200
b5a5d8
Subject: [PATCH GnuPG 01/19] agent: Avoid memory leaks
b5a5d8
b5a5d8
* agent/command.c (cmd_genkey): use goto leave instead of return
b5a5d8
* agent/cvt-openpgp.c (convert_from_openpgp_main): use goto leave
b5a5d8
  instead of return
b5a5d8
* agent/genkey.c (agent_ask_new_passphrase): fix typo to free correct
b5a5d8
  pointer
b5a5d8
  (agent_genkey): release memory
b5a5d8
* agent/gpg-agent.c (check_own_socket): free sockname
b5a5d8
* agent/protect-tool.c (read_key): free buf
b5a5d8
  (agent_askpin): free passphrase
b5a5d8
* agent/protect.c (merge_lists): free newlist
b5a5d8
b5a5d8
--
b5a5d8
b5a5d8
Signed-off-by: Jakub Jelen <jjelen@redhat.com>
b5a5d8
---
b5a5d8
 agent/command.c      |  2 +-
b5a5d8
 agent/cvt-openpgp.c  |  5 ++++-
b5a5d8
 agent/genkey.c       |  7 +++++--
b5a5d8
 agent/gpg-agent.c    | 10 ++++++++--
b5a5d8
 agent/protect-tool.c |  6 +++++-
b5a5d8
 agent/protect.c      |  5 ++++-
b5a5d8
 6 files changed, 27 insertions(+), 8 deletions(-)
b5a5d8
b5a5d8
diff --git a/agent/command.c b/agent/command.c
b5a5d8
index 93cd281e7..b9a1ed038 100644
b5a5d8
--- a/agent/command.c
b5a5d8
+++ b/agent/command.c
b5a5d8
@@ -1021,7 +1021,7 @@ cmd_genkey (assuan_context_t ctx, char *line)
b5a5d8
   if (!rc)
b5a5d8
     rc = assuan_inquire (ctx, "KEYPARAM", &value, &valuelen, MAXLEN_KEYPARAM);
b5a5d8
   if (rc)
b5a5d8
-    return rc;
b5a5d8
+    goto leave;
b5a5d8
 
b5a5d8
   init_membuf (&outbuf, 512);
b5a5d8
 
b5a5d8
diff --git a/agent/cvt-openpgp.c b/agent/cvt-openpgp.c
b5a5d8
index 3da553f95..53c88154b 100644
b5a5d8
--- a/agent/cvt-openpgp.c
b5a5d8
+++ b/agent/cvt-openpgp.c
b5a5d8
@@ -964,7 +964,10 @@ convert_from_openpgp_main (ctrl_t ctrl, gcry_sexp_t s_pgp, int dontcare_exist,
b5a5d8
 
b5a5d8
       pi = xtrycalloc_secure (1, sizeof (*pi) + MAX_PASSPHRASE_LEN + 1);
b5a5d8
       if (!pi)
b5a5d8
-        return gpg_error_from_syserror ();
b5a5d8
+        {
b5a5d8
+          err = gpg_error_from_syserror ();
b5a5d8
+          goto leave;
b5a5d8
+        }
b5a5d8
       pi->max_length = MAX_PASSPHRASE_LEN + 1;
b5a5d8
       pi->min_digits = 0;  /* We want a real passphrase.  */
b5a5d8
       pi->max_digits = 16;
b5a5d8
diff --git a/agent/genkey.c b/agent/genkey.c
b5a5d8
index 9b47f0fac..c7cfc6910 100644
b5a5d8
--- a/agent/genkey.c
b5a5d8
+++ b/agent/genkey.c
b5a5d8
@@ -363,7 +363,7 @@ agent_ask_new_passphrase (ctrl_t ctrl, const char *prompt,
b5a5d8
   if (!pi2)
b5a5d8
     {
b5a5d8
       err = gpg_error_from_syserror ();
b5a5d8
-      xfree (pi2);
b5a5d8
+      xfree (pi);
b5a5d8
       return err;
b5a5d8
     }
b5a5d8
   pi->max_length = MAX_PASSPHRASE_LEN + 1;
b5a5d8
@@ -465,7 +465,10 @@ agent_genkey (ctrl_t ctrl, const char *cache_nonce, time_t timestamp,
b5a5d8
                                         "protect your new key"),
b5a5d8
                                      &passphrase_buffer);
b5a5d8
       if (rc)
b5a5d8
-        return rc;
b5a5d8
+        {
b5a5d8
+          gcry_sexp_release (s_keyparam);
b5a5d8
+          return rc;
b5a5d8
+        }
b5a5d8
       passphrase = passphrase_buffer;
b5a5d8
     }
b5a5d8
 
b5a5d8
diff --git a/agent/gpg-agent.c b/agent/gpg-agent.c
b5a5d8
index 1285db995..8f504191b 100644
b5a5d8
--- a/agent/gpg-agent.c
b5a5d8
+++ b/agent/gpg-agent.c
b5a5d8
@@ -3214,11 +3214,17 @@ check_own_socket (void)
b5a5d8
 
b5a5d8
   sockname = make_filename_try (gnupg_socketdir (), GPG_AGENT_SOCK_NAME, NULL);
b5a5d8
   if (!sockname)
b5a5d8
-    return; /* Out of memory.  */
b5a5d8
+    {
b5a5d8
+      xfree (sockname);
b5a5d8
+      return; /* Out of memory.  */
b5a5d8
+    }
b5a5d8
 
b5a5d8
   err = npth_attr_init (&tattr);
b5a5d8
   if (err)
b5a5d8
-    return;
b5a5d8
+    {
b5a5d8
+      xfree (sockname);
b5a5d8
+      return;
b5a5d8
+    }
b5a5d8
   npth_attr_setdetachstate (&tattr, NPTH_CREATE_DETACHED);
b5a5d8
   err = npth_create (&thread, &tattr, check_own_socket_thread, sockname);
b5a5d8
   if (err)
b5a5d8
diff --git a/agent/protect-tool.c b/agent/protect-tool.c
b5a5d8
index 1fcbd119f..bb17033a8 100644
b5a5d8
--- a/agent/protect-tool.c
b5a5d8
+++ b/agent/protect-tool.c
b5a5d8
@@ -319,6 +319,7 @@ read_key (const char *fname)
b5a5d8
   if (buflen >= 4 && !memcmp (buf, "Key:", 4))
b5a5d8
     {
b5a5d8
       log_error ("Extended key format is not supported by this tool\n");
b5a5d8
+      xfree (buf);
b5a5d8
       return NULL;
b5a5d8
     }
b5a5d8
   key = make_canonical (fname, buf, buflen);
b5a5d8
@@ -793,7 +794,10 @@ agent_askpin (ctrl_t ctrl,
b5a5d8
   passphrase = get_passphrase (0);
b5a5d8
   size = strlen (passphrase);
b5a5d8
   if (size >= pininfo->max_length)
b5a5d8
-    return gpg_error (GPG_ERR_TOO_LARGE);
b5a5d8
+    {
b5a5d8
+      xfree (passphrase);
b5a5d8
+      return gpg_error (GPG_ERR_TOO_LARGE);
b5a5d8
+    }
b5a5d8
 
b5a5d8
   memcpy (&pininfo->pin, passphrase, size);
b5a5d8
   xfree (passphrase);
b5a5d8
diff --git a/agent/protect.c b/agent/protect.c
b5a5d8
index 76ead444b..50b10eb26 100644
b5a5d8
--- a/agent/protect.c
b5a5d8
+++ b/agent/protect.c
b5a5d8
@@ -949,7 +949,10 @@ merge_lists (const unsigned char *protectedkey,
b5a5d8
   /* Copy the cleartext.  */
b5a5d8
   s = cleartext;
b5a5d8
   if (*s != '(' && s[1] != '(')
b5a5d8
-    return gpg_error (GPG_ERR_BUG);  /*we already checked this */
b5a5d8
+    {
b5a5d8
+      xfree (newlist);
b5a5d8
+      return gpg_error (GPG_ERR_BUG);  /*we already checked this */
b5a5d8
+    }
b5a5d8
   s += 2;
b5a5d8
   startpos = s;
b5a5d8
   while ( *s == '(' )
b5a5d8
-- 
b5a5d8
2.30.2
b5a5d8
b5a5d8
b5a5d8
From 93dc0474ea35c0f8f93e0c5eee14cf0157b0d896 Mon Sep 17 00:00:00 2001
b5a5d8
From: Jakub Jelen <jjelen@redhat.com>
b5a5d8
Date: Wed, 7 Apr 2021 18:54:02 +0200
b5a5d8
Subject: [PATCH GnuPG 02/19] dirmgr: clean up memory on error code paths
b5a5d8
b5a5d8
* dirmgr/crlcache.c (finish_sig_check): goto leave instead of return
b5a5d8
* dirmgr/http.c (send_request): free authstr and proxy_authstr
b5a5d8
* dirmgr/ldap.c (start_cert_fetch_ldap): free proxy
b5a5d8
* dirmgr/ocsp.c (check_signature): release s_hash
b5a5d8
b5a5d8
--
b5a5d8
b5a5d8
Signed-off-by: Jakub Jelen <jjelen@redhat.com>
b5a5d8
---
b5a5d8
 dirmngr/crlcache.c | 9 ++++++---
b5a5d8
 dirmngr/http.c     | 6 +++++-
b5a5d8
 dirmngr/ldap.c     | 6 ++++--
b5a5d8
 dirmngr/ocsp.c     | 1 +
b5a5d8
 4 files changed, 16 insertions(+), 6 deletions(-)
b5a5d8
b5a5d8
diff --git a/dirmngr/crlcache.c b/dirmngr/crlcache.c
b5a5d8
index 9d18b721f..d508e173f 100644
b5a5d8
--- a/dirmngr/crlcache.c
b5a5d8
+++ b/dirmngr/crlcache.c
b5a5d8
@@ -1725,7 +1725,8 @@ finish_sig_check (ksba_crl_t crl, gcry_md_hd_t md, int algo,
b5a5d8
         {
b5a5d8
           log_error ("hash algo mismatch: %d announced but %d used\n",
b5a5d8
                      algo, hashalgo);
b5a5d8
-          return gpg_error (GPG_ERR_INV_CRL);
b5a5d8
+          err = gpg_error (GPG_ERR_INV_CRL);
b5a5d8
+          goto leave;
b5a5d8
         }
b5a5d8
       /* Add some restrictions; see ../sm/certcheck.c for details.  */
b5a5d8
       switch (algo)
b5a5d8
@@ -1741,14 +1742,16 @@ finish_sig_check (ksba_crl_t crl, gcry_md_hd_t md, int algo,
b5a5d8
         default:
b5a5d8
           log_error ("PSS hash algorithm '%s' rejected\n",
b5a5d8
                      gcry_md_algo_name (algo));
b5a5d8
-          return gpg_error (GPG_ERR_DIGEST_ALGO);
b5a5d8
+          err = gpg_error (GPG_ERR_DIGEST_ALGO);
b5a5d8
+          goto leave;
b5a5d8
         }
b5a5d8
 
b5a5d8
       if (gcry_md_get_algo_dlen (algo) != saltlen)
b5a5d8
         {
b5a5d8
           log_error ("PSS hash algorithm '%s' rejected due to salt length %u\n",
b5a5d8
                      gcry_md_algo_name (algo), saltlen);
b5a5d8
-          return gpg_error (GPG_ERR_DIGEST_ALGO);
b5a5d8
+          err = gpg_error (GPG_ERR_DIGEST_ALGO);
b5a5d8
+          goto leave;
b5a5d8
         }
b5a5d8
     }
b5a5d8
 
b5a5d8
diff --git a/dirmngr/http.c b/dirmngr/http.c
b5a5d8
index f7f65303b..74ce5f465 100644
b5a5d8
--- a/dirmngr/http.c
b5a5d8
+++ b/dirmngr/http.c
b5a5d8
@@ -2208,7 +2208,11 @@ send_request (ctrl_t ctrl, http_t hd, const char *httphost, const char *auth,
b5a5d8
 
b5a5d8
   p = build_rel_path (hd->uri);
b5a5d8
   if (!p)
b5a5d8
-    return gpg_err_make (default_errsource, gpg_err_code_from_syserror ());
b5a5d8
+    {
b5a5d8
+      xfree (authstr);
b5a5d8
+      xfree (proxy_authstr);
b5a5d8
+      return gpg_err_make (default_errsource, gpg_err_code_from_syserror ());
b5a5d8
+    }
b5a5d8
 
b5a5d8
   if (http_proxy && *http_proxy)
b5a5d8
     {
b5a5d8
diff --git a/dirmngr/ldap.c b/dirmngr/ldap.c
b5a5d8
index ffe54bade..96abc89d0 100644
b5a5d8
--- a/dirmngr/ldap.c
b5a5d8
+++ b/dirmngr/ldap.c
b5a5d8
@@ -563,8 +563,10 @@ start_cert_fetch_ldap (ctrl_t ctrl, cert_fetch_context_t *r_context,
b5a5d8
       use_ldaps = server->use_ldaps;
b5a5d8
     }
b5a5d8
   else /* Use a default server. */
b5a5d8
-    return gpg_error (GPG_ERR_NOT_IMPLEMENTED);
b5a5d8
-
b5a5d8
+    {
b5a5d8
+      xfree (proxy);
b5a5d8
+      return gpg_error (GPG_ERR_NOT_IMPLEMENTED);
b5a5d8
+    }
b5a5d8
 
b5a5d8
   if (!base)
b5a5d8
     base = "";
b5a5d8
diff --git a/dirmngr/ocsp.c b/dirmngr/ocsp.c
b5a5d8
index 6ed180955..6864f9854 100644
b5a5d8
--- a/dirmngr/ocsp.c
b5a5d8
+++ b/dirmngr/ocsp.c
b5a5d8
@@ -534,6 +534,7 @@ check_signature (ctrl_t ctrl,
b5a5d8
       err = ksba_ocsp_get_responder_id (ocsp, &name, &keyid);
b5a5d8
       if (err)
b5a5d8
         {
b5a5d8
+          gcry_sexp_release (s_hash);
b5a5d8
           log_error (_("error getting responder ID: %s\n"),
b5a5d8
                      gcry_strerror (err));
b5a5d8
           return err;
b5a5d8
-- 
b5a5d8
2.30.2
b5a5d8
b5a5d8
b5a5d8
From 7a707a3eff1c3fbe17a74337776871f408377cee Mon Sep 17 00:00:00 2001
b5a5d8
From: Jakub Jelen <jjelen@redhat.com>
b5a5d8
Date: Fri, 9 Apr 2021 16:13:07 +0200
b5a5d8
Subject: [PATCH GnuPG 03/19] g10: Fix memory leaks
b5a5d8
b5a5d8
* g10/card-util.c (change_pin): free answer on errors
b5a5d8
  (ask_card_keyattr): free answer on error
b5a5d8
* g10/cpr.c (do_get_from_fd): free string
b5a5d8
* g10/gpg.c (check_permissions): free dir on weird error
b5a5d8
* g10/import.c (append_new_uid): release knode
b5a5d8
* g10/keyedit.c (menu_set_keyserver_url): free answer
b5a5d8
  (menu_set_keyserver_url): free user
b5a5d8
* g10/keygen.c (print_status_key_not_created): move allocation after
b5a5d8
  sanity check
b5a5d8
  (ask_expire_interval): free answer
b5a5d8
  (card_store_key_with_backup): goto leave instaed of return
b5a5d8
* g10/keyserver.c (parse_keyserver_uri): goto fail instead of return
b5a5d8
* g10/revoke.c (gen_desig_revoke): release kdbhd
b5a5d8
  (gen_desig_revoke): free answer
b5a5d8
* g10/tofu.c (ask_about_binding): free sqerr and response
b5a5d8
* g10/trustdb.c (ask_ownertrust): free pk
b5a5d8
b5a5d8
--
b5a5d8
b5a5d8
Signed-off-by: Jakub Jelen <jjelen@redhat.com>
b5a5d8
---
b5a5d8
 g10/card-util.c | 14 +++++++++++---
b5a5d8
 g10/cpr.c       |  6 +++++-
b5a5d8
 g10/gpg.c       |  1 +
b5a5d8
 g10/import.c    |  5 ++++-
b5a5d8
 g10/keyedit.c   |  8 +++++++-
b5a5d8
 g10/keygen.c    | 15 +++++++++++----
b5a5d8
 g10/keyserver.c |  2 +-
b5a5d8
 g10/revoke.c    |  6 +++++-
b5a5d8
 g10/tofu.c      |  4 ++++
b5a5d8
 g10/trustdb.c   |  1 +
b5a5d8
 10 files changed, 50 insertions(+), 12 deletions(-)
b5a5d8
b5a5d8
diff --git a/g10/card-util.c b/g10/card-util.c
b5a5d8
index 36f096f06..c7df8380d 100644
b5a5d8
--- a/g10/card-util.c
b5a5d8
+++ b/g10/card-util.c
b5a5d8
@@ -127,7 +127,7 @@ change_pin (int unblock_v2, int allow_admin)
b5a5d8
   else
b5a5d8
     for (;;)
b5a5d8
       {
b5a5d8
-	char *answer;
b5a5d8
+	char *answer = NULL;
b5a5d8
 
b5a5d8
 	tty_printf ("\n");
b5a5d8
 	tty_printf ("1 - change PIN\n"
b5a5d8
@@ -140,7 +140,10 @@ change_pin (int unblock_v2, int allow_admin)
b5a5d8
 	answer = cpr_get("cardutil.change_pin.menu",_("Your selection? "));
b5a5d8
 	cpr_kill_prompt();
b5a5d8
 	if (strlen (answer) != 1)
b5a5d8
-	  continue;
b5a5d8
+          {
b5a5d8
+            xfree (answer);
b5a5d8
+            continue;
b5a5d8
+          }
b5a5d8
 
b5a5d8
 	if (*answer == '1')
b5a5d8
 	  {
b5a5d8
@@ -185,8 +188,10 @@ change_pin (int unblock_v2, int allow_admin)
b5a5d8
 	  }
b5a5d8
 	else if (*answer == 'q' || *answer == 'Q')
b5a5d8
 	  {
b5a5d8
+            xfree (answer);
b5a5d8
 	    break;
b5a5d8
 	  }
b5a5d8
+        xfree (answer);
b5a5d8
       }
b5a5d8
 
b5a5d8
   agent_release_card_info (&info;;
b5a5d8
@@ -1450,7 +1455,10 @@ ask_card_keyattr (int keyno, const struct key_attr *current)
b5a5d8
       algo = *answer? atoi (answer) : 0;
b5a5d8
 
b5a5d8
       if (!*answer || algo == 1 || algo == 2)
b5a5d8
-        break;
b5a5d8
+        {
b5a5d8
+          xfree (answer);
b5a5d8
+          break;
b5a5d8
+        }
b5a5d8
       else
b5a5d8
         tty_printf (_("Invalid selection.\n"));
b5a5d8
     }
b5a5d8
diff --git a/g10/cpr.c b/g10/cpr.c
b5a5d8
index 5a39913c5..002656b82 100644
b5a5d8
--- a/g10/cpr.c
b5a5d8
+++ b/g10/cpr.c
b5a5d8
@@ -527,7 +527,11 @@ do_get_from_fd ( const char *keyword, int hidden, int getbool )
b5a5d8
   write_status (STATUS_GOT_IT);
b5a5d8
 
b5a5d8
   if (getbool)	 /* Fixme: is this correct??? */
b5a5d8
-    return (string[0] == 'Y' || string[0] == 'y') ? "" : NULL;
b5a5d8
+    {
b5a5d8
+      char *rv = (string[0] == 'Y' || string[0] == 'y') ? "" : NULL;
b5a5d8
+      xfree (string);
b5a5d8
+      return rv;
b5a5d8
+    }
b5a5d8
 
b5a5d8
   return string;
b5a5d8
 }
b5a5d8
diff --git a/g10/gpg.c b/g10/gpg.c
b5a5d8
index f5623be76..186845cea 100644
b5a5d8
--- a/g10/gpg.c
b5a5d8
+++ b/g10/gpg.c
b5a5d8
@@ -1601,6 +1601,7 @@ check_permissions (const char *path, int item)
b5a5d8
   if (gnupg_stat (dir,&dirbuf) || !S_ISDIR (dirbuf.st_mode))
b5a5d8
     {
b5a5d8
       /* Weird error */
b5a5d8
+      xfree(dir);
b5a5d8
       ret=1;
b5a5d8
       goto end;
b5a5d8
     }
b5a5d8
diff --git a/g10/import.c b/g10/import.c
b5a5d8
index 821ddf0d4..951c33d81 100644
b5a5d8
--- a/g10/import.c
b5a5d8
+++ b/g10/import.c
b5a5d8
@@ -4524,7 +4524,10 @@ append_new_uid (unsigned int options,
b5a5d8
           err = insert_key_origin_uid (n->pkt->pkt.user_id,
b5a5d8
                                        curtime, origin, url);
b5a5d8
           if (err)
b5a5d8
-            return err;
b5a5d8
+            {
b5a5d8
+              release_kbnode (n);
b5a5d8
+              return err;
b5a5d8
+            }
b5a5d8
         }
b5a5d8
 
b5a5d8
       if (n_where)
b5a5d8
diff --git a/g10/keyedit.c b/g10/keyedit.c
b5a5d8
index 531d3e128..902741b5f 100644
b5a5d8
--- a/g10/keyedit.c
b5a5d8
+++ b/g10/keyedit.c
b5a5d8
@@ -5307,7 +5307,10 @@ menu_set_keyserver_url (ctrl_t ctrl, const char *url, kbnode_t pub_keyblock)
b5a5d8
     }
b5a5d8
 
b5a5d8
   if (ascii_strcasecmp (answer, "none") == 0)
b5a5d8
-    uri = NULL;
b5a5d8
+    {
b5a5d8
+      xfree (answer);
b5a5d8
+      uri = NULL;
b5a5d8
+    }
b5a5d8
   else
b5a5d8
     {
b5a5d8
       struct keyserver_spec *keyserver = NULL;
b5a5d8
@@ -5379,12 +5382,14 @@ menu_set_keyserver_url (ctrl_t ctrl, const char *url, kbnode_t pub_keyblock)
b5a5d8
                            uri
b5a5d8
                            ? _("Are you sure you want to replace it? (y/N) ")
b5a5d8
                            : _("Are you sure you want to delete it? (y/N) ")))
b5a5d8
+	                xfree (user);
b5a5d8
 			continue;
b5a5d8
 		    }
b5a5d8
 		  else if (uri == NULL)
b5a5d8
 		    {
b5a5d8
 		      /* There is no current keyserver URL, so there
b5a5d8
 		         is no point in trying to un-set it. */
b5a5d8
+	              xfree (user);
b5a5d8
 		      continue;
b5a5d8
 		    }
b5a5d8
 
b5a5d8
@@ -5397,6 +5402,7 @@ menu_set_keyserver_url (ctrl_t ctrl, const char *url, kbnode_t pub_keyblock)
b5a5d8
 		      log_error ("update_keysig_packet failed: %s\n",
b5a5d8
 				 gpg_strerror (rc));
b5a5d8
 		      xfree (uri);
b5a5d8
+	              xfree (user);
b5a5d8
 		      return 0;
b5a5d8
 		    }
b5a5d8
 		  /* replace the packet */
b5a5d8
diff --git a/g10/keygen.c b/g10/keygen.c
b5a5d8
index 5d85c05d4..f1e4d3638 100644
b5a5d8
--- a/g10/keygen.c
b5a5d8
+++ b/g10/keygen.c
b5a5d8
@@ -237,12 +237,13 @@ print_status_key_not_created (const char *handle)
b5a5d8
 static gpg_error_t
b5a5d8
 write_uid (kbnode_t root, const char *s)
b5a5d8
 {
b5a5d8
-  PACKET *pkt = xmalloc_clear (sizeof *pkt);
b5a5d8
+  PACKET *pkt = NULL;
b5a5d8
   size_t n = strlen (s);
b5a5d8
 
b5a5d8
   if (n > MAX_UID_PACKET_LENGTH - 10)
b5a5d8
     return gpg_error (GPG_ERR_INV_USER_ID);
b5a5d8
 
b5a5d8
+  pkt = xmalloc_clear (sizeof *pkt);
b5a5d8
   pkt->pkttype = PKT_USER_ID;
b5a5d8
   pkt->pkt.user_id = xmalloc_clear (sizeof *pkt->pkt.user_id + n);
b5a5d8
   pkt->pkt.user_id->len = n;
b5a5d8
@@ -2860,7 +2861,10 @@ ask_expire_interval(int object,const char *def_expire)
b5a5d8
 	    xfree(prompt);
b5a5d8
 
b5a5d8
 	    if(*answer=='\0')
b5a5d8
-	      answer=xstrdup(def_expire);
b5a5d8
+              {
b5a5d8
+                xfree (answer);
b5a5d8
+	        answer = xstrdup (def_expire);
b5a5d8
+              }
b5a5d8
 	  }
b5a5d8
 	cpr_kill_prompt();
b5a5d8
 	trim_spaces(answer);
b5a5d8
@@ -5238,12 +5242,15 @@ card_store_key_with_backup (ctrl_t ctrl, PKT_public_key *sub_psk,
b5a5d8
   epoch2isotime (timestamp, (time_t)sk->timestamp);
b5a5d8
   err = hexkeygrip_from_pk (sk, &hexgrip);
b5a5d8
   if (err)
b5a5d8
-    return err;
b5a5d8
+    goto leave;
b5a5d8
 
b5a5d8
   memset(&info, 0, sizeof (info));
b5a5d8
   rc = agent_scd_getattr ("SERIALNO", &info;;
b5a5d8
   if (rc)
b5a5d8
-    return (gpg_error_t)rc;
b5a5d8
+    {
b5a5d8
+      err = (gpg_error_t)rc;
b5a5d8
+      goto leave;
b5a5d8
+    }
b5a5d8
 
b5a5d8
   rc = agent_keytocard (hexgrip, 2, 1, info.serialno, timestamp);
b5a5d8
   xfree (info.serialno);
b5a5d8
diff --git a/g10/keyserver.c b/g10/keyserver.c
b5a5d8
index c56021691..a20ebf24e 100644
b5a5d8
--- a/g10/keyserver.c
b5a5d8
+++ b/g10/keyserver.c
b5a5d8
@@ -284,7 +284,7 @@ parse_keyserver_uri (const char *string,int require_scheme)
b5a5d8
   if(*idx=='\0' || *idx=='[')
b5a5d8
     {
b5a5d8
       if(require_scheme)
b5a5d8
-	return NULL;
b5a5d8
+	goto fail;
b5a5d8
 
b5a5d8
       /* Assume HKP if there is no scheme */
b5a5d8
       assume_hkp=1;
b5a5d8
diff --git a/g10/revoke.c b/g10/revoke.c
b5a5d8
index c0a003b6f..d6cbf93cb 100644
b5a5d8
--- a/g10/revoke.c
b5a5d8
+++ b/g10/revoke.c
b5a5d8
@@ -435,6 +435,7 @@ gen_desig_revoke (ctrl_t ctrl, const char *uname, strlist_t locusr)
b5a5d8
 	iobuf_close(out);
b5a5d8
     release_revocation_reason_info( reason );
b5a5d8
     release_armor_context (afx);
b5a5d8
+    keydb_release (kdbhd);
b5a5d8
     return rc;
b5a5d8
 }
b5a5d8
 
b5a5d8
@@ -804,7 +805,10 @@ ask_revocation_reason( int key_rev, int cert_rev, int hint )
b5a5d8
 	    trim_spaces( answer );
b5a5d8
 	    cpr_kill_prompt();
b5a5d8
 	    if( *answer == 'q' || *answer == 'Q')
b5a5d8
-	      return NULL; /* cancel */
b5a5d8
+              {
b5a5d8
+                xfree (answer);
b5a5d8
+                return NULL; /* cancel */
b5a5d8
+              }
b5a5d8
 	    if( hint && !*answer )
b5a5d8
 		n = hint;
b5a5d8
 	    else if(!digitp( answer ) )
b5a5d8
diff --git a/g10/tofu.c b/g10/tofu.c
b5a5d8
index f49083844..83786a08d 100644
b5a5d8
--- a/g10/tofu.c
b5a5d8
+++ b/g10/tofu.c
b5a5d8
@@ -1687,6 +1687,8 @@ ask_about_binding (ctrl_t ctrl,
b5a5d8
          GPGSQL_ARG_END);
b5a5d8
       if (rc)
b5a5d8
         {
b5a5d8
+          sqlite3_free (sqerr);
b5a5d8
+          sqerr = NULL;
b5a5d8
           rc = gpg_error (GPG_ERR_GENERAL);
b5a5d8
           break;
b5a5d8
         }
b5a5d8
@@ -1972,6 +1974,7 @@ ask_about_binding (ctrl_t ctrl,
b5a5d8
       else if (!response[0])
b5a5d8
         /* Default to unknown.  Don't save it.  */
b5a5d8
         {
b5a5d8
+          xfree (response);
b5a5d8
           tty_printf (_("Defaulting to unknown.\n"));
b5a5d8
           *policy = TOFU_POLICY_UNKNOWN;
b5a5d8
           break;
b5a5d8
@@ -1983,6 +1986,7 @@ ask_about_binding (ctrl_t ctrl,
b5a5d8
           if (choice)
b5a5d8
             {
b5a5d8
               int c = ((size_t) choice - (size_t) choices) / 2;
b5a5d8
+              xfree (response);
b5a5d8
 
b5a5d8
               switch (c)
b5a5d8
                 {
b5a5d8
diff --git a/g10/trustdb.c b/g10/trustdb.c
b5a5d8
index 43bce0769..9ef4644bf 100644
b5a5d8
--- a/g10/trustdb.c
b5a5d8
+++ b/g10/trustdb.c
b5a5d8
@@ -1430,6 +1430,7 @@ ask_ownertrust (ctrl_t ctrl, u32 *kid, int minimum)
b5a5d8
     {
b5a5d8
       log_error (_("public key %s not found: %s\n"),
b5a5d8
                  keystr(kid), gpg_strerror (rc) );
b5a5d8
+      free_public_key (pk);
b5a5d8
       return TRUST_UNKNOWN;
b5a5d8
     }
b5a5d8
 
b5a5d8
-- 
b5a5d8
2.30.2
b5a5d8
b5a5d8
b5a5d8
From 0dabf0cffb1d67812c50a4f727398b59f93270a6 Mon Sep 17 00:00:00 2001
b5a5d8
From: Jakub Jelen <jjelen@redhat.com>
b5a5d8
Date: Mon, 12 Apr 2021 14:05:17 +0200
b5a5d8
Subject: [PATCH GnuPG 04/19] sm: Avoid memory leaks and double double-free
b5a5d8
b5a5d8
* sm/certcheck.c (extract_pss_params): Avoid double free
b5a5d8
* sm/decrypt.c (gpgsm_decrypt): goto leave instead of return
b5a5d8
* sm/encrypt.c (encrypt_dek): release s_pkey
b5a5d8
* sm/server.c (cmd_export): free list
b5a5d8
  (do_listkeys): free lists
b5a5d8
b5a5d8
--
b5a5d8
b5a5d8
Signed-off-by: Jakub Jelen <jjelen@redhat.com>
b5a5d8
---
b5a5d8
 sm/certcheck.c |  1 -
b5a5d8
 sm/decrypt.c   |  5 ++++-
b5a5d8
 sm/encrypt.c   |  1 +
b5a5d8
 sm/server.c    | 24 +++++++++++++++++++-----
b5a5d8
 4 files changed, 24 insertions(+), 7 deletions(-)
b5a5d8
b5a5d8
diff --git a/sm/certcheck.c b/sm/certcheck.c
b5a5d8
index fca45759b..f4db858c3 100644
b5a5d8
--- a/sm/certcheck.c
b5a5d8
+++ b/sm/certcheck.c
b5a5d8
@@ -294,7 +294,6 @@ extract_pss_params (gcry_sexp_t s_sig, int *r_algo, unsigned int *r_saltlen)
b5a5d8
   if (*r_saltlen < 20)
b5a5d8
     {
b5a5d8
       log_error ("length of PSS salt too short\n");
b5a5d8
-      gcry_sexp_release (s_sig);
b5a5d8
       return gpg_error (GPG_ERR_DIGEST_ALGO);
b5a5d8
     }
b5a5d8
   if (!*r_algo)
b5a5d8
diff --git a/sm/decrypt.c b/sm/decrypt.c
b5a5d8
index aa91b370d..f7f91c466 100644
b5a5d8
--- a/sm/decrypt.c
b5a5d8
+++ b/sm/decrypt.c
b5a5d8
@@ -755,7 +755,10 @@ gpgsm_decrypt (ctrl_t ctrl, int in_fd, estream_t out_fp)
b5a5d8
           dfparm.mode = mode;
b5a5d8
           dfparm.blklen = gcry_cipher_get_algo_blklen (algo);
b5a5d8
           if (dfparm.blklen > sizeof (dfparm.helpblock))
b5a5d8
-            return gpg_error (GPG_ERR_BUG);
b5a5d8
+            {
b5a5d8
+              rc = gpg_error (GPG_ERR_BUG);
b5a5d8
+              goto leave;
b5a5d8
+            }
b5a5d8
 
b5a5d8
           rc = ksba_cms_get_content_enc_iv (cms,
b5a5d8
                                             dfparm.iv,
b5a5d8
diff --git a/sm/encrypt.c b/sm/encrypt.c
b5a5d8
index 92ca341f5..ba2428e9a 100644
b5a5d8
--- a/sm/encrypt.c
b5a5d8
+++ b/sm/encrypt.c
b5a5d8
@@ -473,6 +473,7 @@ encrypt_dek (const DEK dek, ksba_cert_t cert, int pk_algo,
b5a5d8
       rc = encode_session_key (dek, &s_data);
b5a5d8
       if (rc)
b5a5d8
         {
b5a5d8
+          gcry_sexp_release (s_pkey);
b5a5d8
           log_error ("encode_session_key failed: %s\n", gpg_strerror (rc));
b5a5d8
           return rc;
b5a5d8
         }
b5a5d8
diff --git a/sm/server.c b/sm/server.c
b5a5d8
index 874f0db89..871cc4b31 100644
b5a5d8
--- a/sm/server.c
b5a5d8
+++ b/sm/server.c
b5a5d8
@@ -724,8 +724,13 @@ cmd_export (assuan_context_t ctx, char *line)
b5a5d8
 
b5a5d8
   if (opt_secret)
b5a5d8
     {
b5a5d8
-      if (!list || !*list->d)
b5a5d8
+      if (!list)
b5a5d8
         return set_error (GPG_ERR_NO_DATA, "No key given");
b5a5d8
+      if (!*list->d)
b5a5d8
+        {
b5a5d8
+          free_strlist (list);
b5a5d8
+          return set_error (GPG_ERR_NO_DATA, "No key given");
b5a5d8
+        }
b5a5d8
       if (list->next)
b5a5d8
         return set_error (GPG_ERR_TOO_MANY, "Only one key allowed");
b5a5d8
   }
b5a5d8
@@ -1014,17 +1019,26 @@ do_listkeys (assuan_context_t ctx, char *line, int mode)
b5a5d8
       int outfd = translate_sys2libc_fd (assuan_get_output_fd (ctx), 1);
b5a5d8
 
b5a5d8
       if ( outfd == -1 )
b5a5d8
-        return set_error (GPG_ERR_ASS_NO_OUTPUT, NULL);
b5a5d8
+        {
b5a5d8
+          free_strlist (list);
b5a5d8
+          return set_error (GPG_ERR_ASS_NO_OUTPUT, NULL);
b5a5d8
+        }
b5a5d8
       fp = es_fdopen_nc (outfd, "w");
b5a5d8
       if (!fp)
b5a5d8
-        return set_error (gpg_err_code_from_syserror (), "es_fdopen() failed");
b5a5d8
+        {
b5a5d8
+          free_strlist (list);
b5a5d8
+          return set_error (gpg_err_code_from_syserror (), "es_fdopen() failed");
b5a5d8
+        }
b5a5d8
     }
b5a5d8
   else
b5a5d8
     {
b5a5d8
       fp = es_fopencookie (ctx, "w", data_line_cookie_functions);
b5a5d8
       if (!fp)
b5a5d8
-        return set_error (GPG_ERR_ASS_GENERAL,
b5a5d8
-                          "error setting up a data stream");
b5a5d8
+        {
b5a5d8
+          free_strlist (list);
b5a5d8
+          return set_error (GPG_ERR_ASS_GENERAL,
b5a5d8
+                            "error setting up a data stream");
b5a5d8
+        }
b5a5d8
     }
b5a5d8
 
b5a5d8
   ctrl->with_colons = 1;
b5a5d8
-- 
b5a5d8
2.30.2
b5a5d8
b5a5d8
b5a5d8
From febbe77870b51e4e1158ae9efeaa0f3aad69a495 Mon Sep 17 00:00:00 2001
b5a5d8
From: Jakub Jelen <jjelen@redhat.com>
b5a5d8
Date: Mon, 12 Apr 2021 14:48:59 +0200
b5a5d8
Subject: [PATCH GnuPG 05/19] tools: Avoid memory leak sfrom gpgspilt
b5a5d8
b5a5d8
* tools/gpgsplit.c (write_part): free blob
b5a5d8
b5a5d8
--
b5a5d8
b5a5d8
Signed-off-by: Jakub Jelen <jjelen@redhat.com>
b5a5d8
---
b5a5d8
 tools/gpgsplit.c | 1 +
b5a5d8
 1 file changed, 1 insertion(+)
b5a5d8
b5a5d8
diff --git a/tools/gpgsplit.c b/tools/gpgsplit.c
b5a5d8
index cc7bf8ef5..93458068c 100644
b5a5d8
--- a/tools/gpgsplit.c
b5a5d8
+++ b/tools/gpgsplit.c
b5a5d8
@@ -620,6 +620,7 @@ write_part (FILE *fpin, unsigned long pktlen,
b5a5d8
             }
b5a5d8
         }
b5a5d8
 
b5a5d8
+      xfree (blob);
b5a5d8
       goto ready;
b5a5d8
     }
b5a5d8
 
b5a5d8
-- 
b5a5d8
2.30.2
b5a5d8
b5a5d8
b5a5d8
From 1cd048ba37786f46aabf3efdc3c245b75244dc26 Mon Sep 17 00:00:00 2001
b5a5d8
From: Jakub Jelen <jjelen@redhat.com>
b5a5d8
Date: Mon, 12 Apr 2021 19:19:59 +0200
b5a5d8
Subject: [PATCH GnuPG 06/19] agent: Fix memory leaks
b5a5d8
b5a5d8
* agent/call-daemon.c (daemon_start): free wctp
b5a5d8
* agent/call-scd.c (agent_card_pksign): return error instead of noop
b5a5d8
  (card_keyinfo_cb): free keyinfo
b5a5d8
* agent/protect.c (agent_get_shadow_info_type): allocate only as a last
b5a5d8
  action
b5a5d8
  (agent_is_tpm2_key): Free buf
b5a5d8
b5a5d8
--
b5a5d8
b5a5d8
Signed-off-by: Jakub Jelen <jjelen@redhat.com>
b5a5d8
---
b5a5d8
 agent/call-daemon.c |  2 ++
b5a5d8
 agent/call-scd.c    |  4 +++-
b5a5d8
 agent/protect.c     | 17 +++++++++--------
b5a5d8
 3 files changed, 14 insertions(+), 9 deletions(-)
b5a5d8
b5a5d8
diff --git a/agent/call-daemon.c b/agent/call-daemon.c
b5a5d8
index 144400875..3bf6bb793 100644
b5a5d8
--- a/agent/call-daemon.c
b5a5d8
+++ b/agent/call-daemon.c
b5a5d8
@@ -512,6 +512,8 @@ daemon_start (enum daemon_type type, ctrl_t ctrl)
b5a5d8
           log_error ("error spawning wait_child_thread: %s\n", strerror (err));
b5a5d8
         npth_attr_destroy (&tattr);
b5a5d8
       }
b5a5d8
+    else
b5a5d8
+      xfree (wctp);
b5a5d8
   }
b5a5d8
 
b5a5d8
  leave:
b5a5d8
diff --git a/agent/call-scd.c b/agent/call-scd.c
b5a5d8
index 3ede33c1d..f060541a3 100644
b5a5d8
--- a/agent/call-scd.c
b5a5d8
+++ b/agent/call-scd.c
b5a5d8
@@ -487,7 +487,7 @@ agent_card_pksign (ctrl_t ctrl,
b5a5d8
   /* FIXME: In the mdalgo case (INDATA,INDATALEN) might be long and
b5a5d8
    * thus we can't convey it on a single Assuan line.  */
b5a5d8
   if (!mdalgo)
b5a5d8
-    gpg_error (GPG_ERR_NOT_IMPLEMENTED);
b5a5d8
+    return gpg_error (GPG_ERR_NOT_IMPLEMENTED);
b5a5d8
 
b5a5d8
   if (indatalen*2 + 50 > DIM(line))
b5a5d8
     return unlock_scd (ctrl, gpg_error (GPG_ERR_GENERAL));
b5a5d8
@@ -941,6 +941,7 @@ card_keyinfo_cb (void *opaque, const char *line)
b5a5d8
       if (!keyinfo)
b5a5d8
         {
b5a5d8
         alloc_error:
b5a5d8
+          xfree (keyinfo);
b5a5d8
           if (!parm->error)
b5a5d8
             parm->error = gpg_error_from_syserror ();
b5a5d8
           return 0;
b5a5d8
@@ -952,6 +953,7 @@ card_keyinfo_cb (void *opaque, const char *line)
b5a5d8
       if (n != 40)
b5a5d8
         {
b5a5d8
         parm_error:
b5a5d8
+          xfree (keyinfo);
b5a5d8
           if (!parm->error)
b5a5d8
             parm->error = gpg_error (GPG_ERR_ASS_PARAMETER);
b5a5d8
           return 0;
b5a5d8
diff --git a/agent/protect.c b/agent/protect.c
b5a5d8
index 50b10eb26..72169429d 100644
b5a5d8
--- a/agent/protect.c
b5a5d8
+++ b/agent/protect.c
b5a5d8
@@ -1663,13 +1663,6 @@ agent_get_shadow_info_type (const unsigned char *shadowkey,
b5a5d8
   n = snext (&s);
b5a5d8
   if (!n)
b5a5d8
     return gpg_error (GPG_ERR_INV_SEXP);
b5a5d8
-  if (shadow_type) {
b5a5d8
-    char *buf = xtrymalloc(n+1);
b5a5d8
-    memcpy(buf, s, n);
b5a5d8
-    buf[n] = '\0';
b5a5d8
-    *shadow_type = buf;
b5a5d8
-  }
b5a5d8
-
b5a5d8
   if (smatch (&s, n, "t1-v1") || smatch(&s, n, "tpm2-v1"))
b5a5d8
     {
b5a5d8
       if (*s != '(')
b5a5d8
@@ -1679,6 +1672,14 @@ agent_get_shadow_info_type (const unsigned char *shadowkey,
b5a5d8
     }
b5a5d8
   else
b5a5d8
     return gpg_error (GPG_ERR_UNSUPPORTED_PROTOCOL);
b5a5d8
+
b5a5d8
+  if (shadow_type) {
b5a5d8
+    char *buf = xtrymalloc(n+1);
b5a5d8
+    memcpy(buf, s, n);
b5a5d8
+    buf[n] = '\0';
b5a5d8
+    *shadow_type = buf;
b5a5d8
+  }
b5a5d8
+
b5a5d8
   return 0;
b5a5d8
 }
b5a5d8
 
b5a5d8
@@ -1704,9 +1705,9 @@ agent_is_tpm2_key (gcry_sexp_t s_skey)
b5a5d8
     return 0;
b5a5d8
 
b5a5d8
   err = agent_get_shadow_info_type (buf, NULL, &type);
b5a5d8
+  xfree (buf);
b5a5d8
   if (err)
b5a5d8
     return 0;
b5a5d8
-  xfree (buf);
b5a5d8
 
b5a5d8
   err = strcmp (type, "tpm2-v1") == 0;
b5a5d8
   xfree (type);
b5a5d8
-- 
b5a5d8
2.30.2
b5a5d8
b5a5d8
b5a5d8
From 9d206e1dfabb965e97723dd799d0f7b3be04116d Mon Sep 17 00:00:00 2001
b5a5d8
From: Jakub Jelen <jjelen@redhat.com>
b5a5d8
Date: Mon, 12 Apr 2021 19:29:21 +0200
b5a5d8
Subject: [PATCH GnuPG 07/19] common: Avoid double-free
b5a5d8
b5a5d8
* common/name-value.c (do_nvc_parse): reset to null after ownership
b5a5d8
  change
b5a5d8
b5a5d8
--
b5a5d8
b5a5d8
Signed-off-by: Jakub Jelen <jjelen@redhat.com>
b5a5d8
---
b5a5d8
 common/name-value.c | 1 +
b5a5d8
 1 file changed, 1 insertion(+)
b5a5d8
b5a5d8
diff --git a/common/name-value.c b/common/name-value.c
b5a5d8
index 0bd205b7d..39c3244e9 100644
b5a5d8
--- a/common/name-value.c
b5a5d8
+++ b/common/name-value.c
b5a5d8
@@ -724,6 +724,7 @@ do_nvc_parse (nvc_t *result, int *errlinep, estream_t stream,
b5a5d8
       if (raw_value)
b5a5d8
 	{
b5a5d8
 	  err = _nvc_add (*result, name, NULL, raw_value, 1);
b5a5d8
+          name = NULL;
b5a5d8
 	  if (err)
b5a5d8
 	    goto leave;
b5a5d8
 	}
b5a5d8
-- 
b5a5d8
2.30.2
b5a5d8
b5a5d8
b5a5d8
From 33317744850d10a03ad4215a329a7d4bc3837234 Mon Sep 17 00:00:00 2001
b5a5d8
From: Jakub Jelen <jjelen@redhat.com>
b5a5d8
Date: Mon, 12 Apr 2021 19:48:31 +0200
b5a5d8
Subject: [PATCH GnuPG 08/19] dirmgr: Avoid double free
b5a5d8
b5a5d8
* dirmgr/http.c (http_prepare_redirect): Avoid double free
b5a5d8
* dirmgr/ocsp.c (check_signature): Initialize pointer
b5a5d8
b5a5d8
--
b5a5d8
b5a5d8
Signed-off-by: Jakub Jelen <jjelen@redhat.com>
b5a5d8
---
b5a5d8
 dirmngr/http.c | 2 --
b5a5d8
 dirmngr/ocsp.c | 2 +-
b5a5d8
 2 files changed, 1 insertion(+), 3 deletions(-)
b5a5d8
b5a5d8
diff --git a/dirmngr/http.c b/dirmngr/http.c
b5a5d8
index 74ce5f465..c662b1b95 100644
b5a5d8
--- a/dirmngr/http.c
b5a5d8
+++ b/dirmngr/http.c
b5a5d8
@@ -3681,7 +3681,6 @@ http_prepare_redirect (http_redir_info_t *info, unsigned int status_code,
b5a5d8
       if (!newurl)
b5a5d8
         {
b5a5d8
           err = gpg_error_from_syserror ();
b5a5d8
-          http_release_parsed_uri (locuri);
b5a5d8
           return err;
b5a5d8
         }
b5a5d8
     }
b5a5d8
@@ -3700,7 +3699,6 @@ http_prepare_redirect (http_redir_info_t *info, unsigned int status_code,
b5a5d8
       if (!newurl)
b5a5d8
         {
b5a5d8
           err = gpg_error_from_syserror ();
b5a5d8
-          http_release_parsed_uri (locuri);
b5a5d8
           return err;
b5a5d8
         }
b5a5d8
     }
b5a5d8
diff --git a/dirmngr/ocsp.c b/dirmngr/ocsp.c
b5a5d8
index 6864f9854..6ec760d81 100644
b5a5d8
--- a/dirmngr/ocsp.c
b5a5d8
+++ b/dirmngr/ocsp.c
b5a5d8
@@ -450,7 +450,7 @@ check_signature (ctrl_t ctrl,
b5a5d8
 {
b5a5d8
   gpg_error_t err;
b5a5d8
   int algo, cert_idx;
b5a5d8
-  gcry_sexp_t s_hash;
b5a5d8
+  gcry_sexp_t s_hash = NULL;
b5a5d8
   ksba_cert_t cert;
b5a5d8
   const char *s;
b5a5d8
 
b5a5d8
-- 
b5a5d8
2.30.2
b5a5d8
b5a5d8
b5a5d8
From c87d40395b8f24426645cc491dca5cf910755395 Mon Sep 17 00:00:00 2001
b5a5d8
From: Jakub Jelen <jjelen@redhat.com>
b5a5d8
Date: Mon, 12 Apr 2021 20:05:48 +0200
b5a5d8
Subject: [PATCH GnuPG 09/19] g10: Avoid memory leaks
b5a5d8
b5a5d8
* g10/call-agent.c (card_keyinfo_cb): free keyinfo
b5a5d8
* g10/keyedit.c (menu_set_keyserver_url): properly enclose the block
b5a5d8
* g10/keygen.c (gen_card_key): free pk and pkt
b5a5d8
b5a5d8
--
b5a5d8
b5a5d8
Signed-off-by: Jakub Jelen <jjelen@redhat.com>
b5a5d8
---
b5a5d8
 g10/call-agent.c |  2 ++
b5a5d8
 g10/keyedit.c    |  8 +++++---
b5a5d8
 g10/keygen.c     | 12 ++++++++++--
b5a5d8
 3 files changed, 17 insertions(+), 5 deletions(-)
b5a5d8
b5a5d8
diff --git a/g10/call-agent.c b/g10/call-agent.c
b5a5d8
index 83355454a..c9cbcd4e5 100644
b5a5d8
--- a/g10/call-agent.c
b5a5d8
+++ b/g10/call-agent.c
b5a5d8
@@ -1729,6 +1729,7 @@ card_keyinfo_cb (void *opaque, const char *line)
b5a5d8
       if (!keyinfo)
b5a5d8
         {
b5a5d8
         alloc_error:
b5a5d8
+          xfree (keyinfo);
b5a5d8
           if (!parm->error)
b5a5d8
             parm->error = gpg_error_from_syserror ();
b5a5d8
           return 0;
b5a5d8
@@ -1740,6 +1741,7 @@ card_keyinfo_cb (void *opaque, const char *line)
b5a5d8
       if (n != 40)
b5a5d8
         {
b5a5d8
         parm_error:
b5a5d8
+          xfree (keyinfo);
b5a5d8
           if (!parm->error)
b5a5d8
             parm->error = gpg_error (GPG_ERR_ASS_PARAMETER);
b5a5d8
           return 0;
b5a5d8
diff --git a/g10/keyedit.c b/g10/keyedit.c
b5a5d8
index 902741b5f..91731a271 100644
b5a5d8
--- a/g10/keyedit.c
b5a5d8
+++ b/g10/keyedit.c
b5a5d8
@@ -5382,14 +5382,16 @@ menu_set_keyserver_url (ctrl_t ctrl, const char *url, kbnode_t pub_keyblock)
b5a5d8
                            uri
b5a5d8
                            ? _("Are you sure you want to replace it? (y/N) ")
b5a5d8
                            : _("Are you sure you want to delete it? (y/N) ")))
b5a5d8
-	                xfree (user);
b5a5d8
-			continue;
b5a5d8
+		        {
b5a5d8
+			  xfree (user);
b5a5d8
+			  continue;
b5a5d8
+		        }
b5a5d8
 		    }
b5a5d8
 		  else if (uri == NULL)
b5a5d8
 		    {
b5a5d8
 		      /* There is no current keyserver URL, so there
b5a5d8
 		         is no point in trying to un-set it. */
b5a5d8
-	              xfree (user);
b5a5d8
+		      xfree (user);
b5a5d8
 		      continue;
b5a5d8
 		    }
b5a5d8
 
b5a5d8
diff --git a/g10/keygen.c b/g10/keygen.c
b5a5d8
index f1e4d3638..82f6bb880 100644
b5a5d8
--- a/g10/keygen.c
b5a5d8
+++ b/g10/keygen.c
b5a5d8
@@ -6140,12 +6140,20 @@ gen_card_key (int keyno, int algo, int is_primary, kbnode_t pub_root,
b5a5d8
      the self-signatures. */
b5a5d8
   err = agent_readkey (NULL, 1, keyid, &public);
b5a5d8
   if (err)
b5a5d8
-    return err;
b5a5d8
+    {
b5a5d8
+      xfree (pkt);
b5a5d8
+      xfree (pk);
b5a5d8
+      return err;
b5a5d8
+    }
b5a5d8
   err = gcry_sexp_sscan (&s_key, NULL, public,
b5a5d8
                          gcry_sexp_canon_len (public, 0, NULL, NULL));
b5a5d8
   xfree (public);
b5a5d8
   if (err)
b5a5d8
-    return err;
b5a5d8
+    {
b5a5d8
+      xfree (pkt);
b5a5d8
+      xfree (pk);
b5a5d8
+      return err;
b5a5d8
+    }
b5a5d8
 
b5a5d8
   if (algo == PUBKEY_ALGO_RSA)
b5a5d8
     err = key_from_sexp (pk->pkey, s_key, "public-key", "ne");
b5a5d8
-- 
b5a5d8
2.30.2
b5a5d8
b5a5d8
b5a5d8
From bb6e1e13d9440816c60013a50d426b7ccd6c0288 Mon Sep 17 00:00:00 2001
b5a5d8
From: Jakub Jelen <jjelen@redhat.com>
b5a5d8
Date: Mon, 12 Apr 2021 21:59:17 +0200
b5a5d8
Subject: [PATCH GnuPG 10/19] kbx: Avoid uninitialized read
b5a5d8
b5a5d8
* kbx/kbx-client-util.c (datastream_thread): Initialize pointer
b5a5d8
* kbx/keybox-dump.c (_keybox_dump_cut_records): free blob
b5a5d8
* kbx/kbxserver.c (kbxd_start_command_handler): do not free passed ctrl
b5a5d8
* kbx/keyboxd.c (check_own_socket): free sockname
b5a5d8
b5a5d8
--
b5a5d8
b5a5d8
Signed-off-by: Jakub Jelen <jjelen@redhat.com>
b5a5d8
---
b5a5d8
 kbx/kbx-client-util.c | 2 +-
b5a5d8
 kbx/kbxserver.c       | 1 -
b5a5d8
 kbx/keybox-dump.c     | 4 +++-
b5a5d8
 kbx/keyboxd.c         | 5 ++++-
b5a5d8
 4 files changed, 8 insertions(+), 4 deletions(-)
b5a5d8
b5a5d8
diff --git a/kbx/kbx-client-util.c b/kbx/kbx-client-util.c
b5a5d8
index bd71cf2ba..07370319b 100644
b5a5d8
--- a/kbx/kbx-client-util.c
b5a5d8
+++ b/kbx/kbx-client-util.c
b5a5d8
@@ -176,7 +176,7 @@ datastream_thread (void *arg)
b5a5d8
   int rc;
b5a5d8
   unsigned char lenbuf[4];
b5a5d8
   size_t nread, datalen;
b5a5d8
-  char *data, *tmpdata;
b5a5d8
+  char *data = NULL, *tmpdata;
b5a5d8
 
b5a5d8
   /* log_debug ("%s: started\n", __func__); */
b5a5d8
   while (kcd->fp)
b5a5d8
diff --git a/kbx/kbxserver.c b/kbx/kbxserver.c
b5a5d8
index 55b478586..0b76cde31 100644
b5a5d8
--- a/kbx/kbxserver.c
b5a5d8
+++ b/kbx/kbxserver.c
b5a5d8
@@ -844,7 +844,6 @@ kbxd_start_command_handler (ctrl_t ctrl, gnupg_fd_t fd, unsigned int session_id)
b5a5d8
     {
b5a5d8
       log_error (_("can't allocate control structure: %s\n"),
b5a5d8
                  gpg_strerror (gpg_error_from_syserror ()));
b5a5d8
-      xfree (ctrl);
b5a5d8
       return;
b5a5d8
     }
b5a5d8
   ctrl->server_local->client_pid = ASSUAN_INVALID_PID;
b5a5d8
diff --git a/kbx/keybox-dump.c b/kbx/keybox-dump.c
b5a5d8
index 3e66b72a1..38608ceaa 100644
b5a5d8
--- a/kbx/keybox-dump.c
b5a5d8
+++ b/kbx/keybox-dump.c
b5a5d8
@@ -881,7 +881,7 @@ _keybox_dump_cut_records (const char *filename, unsigned long from,
b5a5d8
                           unsigned long to, FILE *outfp)
b5a5d8
 {
b5a5d8
   estream_t fp;
b5a5d8
-  KEYBOXBLOB blob;
b5a5d8
+  KEYBOXBLOB blob = NULL;
b5a5d8
   int rc;
b5a5d8
   unsigned long recno = 0;
b5a5d8
 
b5a5d8
@@ -902,6 +902,7 @@ _keybox_dump_cut_records (const char *filename, unsigned long from,
b5a5d8
             }
b5a5d8
         }
b5a5d8
       _keybox_release_blob (blob);
b5a5d8
+      blob = NULL;
b5a5d8
       recno++;
b5a5d8
     }
b5a5d8
   if (rc == -1)
b5a5d8
@@ -909,6 +910,7 @@ _keybox_dump_cut_records (const char *filename, unsigned long from,
b5a5d8
   if (rc)
b5a5d8
     fprintf (stderr, "error reading '%s': %s\n", filename, gpg_strerror (rc));
b5a5d8
  leave:
b5a5d8
+  _keybox_release_blob (blob);
b5a5d8
   if (fp != es_stdin)
b5a5d8
     es_fclose (fp);
b5a5d8
   return rc;
b5a5d8
diff --git a/kbx/keyboxd.c b/kbx/keyboxd.c
b5a5d8
index 76a0694a4..3f759e6f7 100644
b5a5d8
--- a/kbx/keyboxd.c
b5a5d8
+++ b/kbx/keyboxd.c
b5a5d8
@@ -1795,7 +1795,10 @@ check_own_socket (void)
b5a5d8
 
b5a5d8
   err = npth_attr_init (&tattr);
b5a5d8
   if (err)
b5a5d8
-    return;
b5a5d8
+    {
b5a5d8
+      xfree (sockname);
b5a5d8
+      return;
b5a5d8
+    }
b5a5d8
   npth_attr_setdetachstate (&tattr, NPTH_CREATE_DETACHED);
b5a5d8
   err = npth_create (&thread, &tattr, check_own_socket_thread, sockname);
b5a5d8
   if (err)
b5a5d8
-- 
b5a5d8
2.30.2
b5a5d8
b5a5d8
b5a5d8
From 7f54495586491b18b5e1088ecf5538c0343f90e7 Mon Sep 17 00:00:00 2001
b5a5d8
From: Jakub Jelen <jjelen@redhat.com>
b5a5d8
Date: Tue, 13 Apr 2021 14:02:18 +0200
b5a5d8
Subject: [PATCH GnuPG 11/19] scd: avoid memory leaks
b5a5d8
b5a5d8
* scd/app-p15.c (send_certinfo): free labelbuf
b5a5d8
  (do_sign): goto leave instead of return
b5a5d8
* scd/app-piv.c (do_sign): goto leave instead of return, fix typo in
b5a5d8
  variable name, avoid using uninitialized variables
b5a5d8
* scd/command.c (cmd_genkey): goto leave instead of return
b5a5d8
b5a5d8
--
b5a5d8
b5a5d8
Signed-off-by: Jakub Jelen <jjelen@redhat.com>
b5a5d8
---
b5a5d8
 scd/app-p15.c |  5 +++--
b5a5d8
 scd/app-piv.c |  6 +++---
b5a5d8
 scd/command.c | 10 ++++++++--
b5a5d8
 3 files changed, 14 insertions(+), 7 deletions(-)
b5a5d8
b5a5d8
diff --git a/scd/app-p15.c b/scd/app-p15.c
b5a5d8
index 90f6b4c99..9eeeed960 100644
b5a5d8
--- a/scd/app-p15.c
b5a5d8
+++ b/scd/app-p15.c
b5a5d8
@@ -3851,6 +3851,7 @@ send_certinfo (app_t app, ctrl_t ctrl, const char *certtype,
b5a5d8
                         labelbuf, strlen (labelbuf),
b5a5d8
                         NULL, (size_t)0);
b5a5d8
       xfree (buf);
b5a5d8
+      xfree (labelbuf);
b5a5d8
     }
b5a5d8
   return 0;
b5a5d8
 }
b5a5d8
@@ -5461,7 +5462,7 @@ do_sign (app_t app, ctrl_t ctrl, const char *keyidstr, int hashalgo,
b5a5d8
   if (err)
b5a5d8
     {
b5a5d8
       log_error ("p15: MSE failed: %s\n", gpg_strerror (err));
b5a5d8
-      return err;
b5a5d8
+      goto leave;
b5a5d8
     }
b5a5d8
 
b5a5d8
   /* Now that we have all the information available run the actual PIN
b5a5d8
@@ -5500,7 +5501,7 @@ do_sign (app_t app, ctrl_t ctrl, const char *keyidstr, int hashalgo,
b5a5d8
   if (err)
b5a5d8
     {
b5a5d8
       log_error ("p15: MSE failed: %s\n", gpg_strerror (err));
b5a5d8
-      return err;
b5a5d8
+      goto leave;
b5a5d8
     }
b5a5d8
 
b5a5d8
   if (prkdf->keyalgo == GCRY_PK_RSA && prkdf->keynbits > 2048)
b5a5d8
diff --git a/scd/app-piv.c b/scd/app-piv.c
b5a5d8
index ead1b1974..143cc047a 100644
b5a5d8
--- a/scd/app-piv.c
b5a5d8
+++ b/scd/app-piv.c
b5a5d8
@@ -2175,7 +2175,7 @@ do_sign (app_t app, ctrl_t ctrl, const char *keyidstr, int hashalgo,
b5a5d8
   unsigned char oidbuf[64];
b5a5d8
   size_t oidbuflen;
b5a5d8
   unsigned char *outdata = NULL;
b5a5d8
-  size_t outdatalen;
b5a5d8
+  size_t outdatalen = 0;
b5a5d8
   const unsigned char *s;
b5a5d8
   size_t n;
b5a5d8
   int keyref, mechanism;
b5a5d8
@@ -2357,7 +2357,7 @@ do_sign (app_t app, ctrl_t ctrl, const char *keyidstr, int hashalgo,
b5a5d8
   /* Now verify the Application PIN.  */
b5a5d8
   err = verify_chv (app, ctrl, 0x80, force_verify, pincb, pincb_arg);
b5a5d8
   if (err)
b5a5d8
-    return err;
b5a5d8
+    goto leave;
b5a5d8
 
b5a5d8
   /* Build the Dynamic Authentication Template.  */
b5a5d8
   err = concat_tlv_list (0, &apdudata, &apdudatalen,
b5a5d8
@@ -2403,7 +2403,7 @@ do_sign (app_t app, ctrl_t ctrl, const char *keyidstr, int hashalgo,
b5a5d8
             goto bad_der;
b5a5d8
           log_assert (n >= (rval-s)+rlen);
b5a5d8
           sval = find_tlv (rval+rlen, n-((rval-s)+rlen), 0x02, &slen);
b5a5d8
-          if (!rval)
b5a5d8
+          if (!sval)
b5a5d8
             goto bad_der;
b5a5d8
           rlenx = slenx = 0;
b5a5d8
           if (rlen > slen)
b5a5d8
diff --git a/scd/command.c b/scd/command.c
b5a5d8
index 11d61648b..cb0dd379a 100644
b5a5d8
--- a/scd/command.c
b5a5d8
+++ b/scd/command.c
b5a5d8
@@ -1438,7 +1438,10 @@ cmd_genkey (assuan_context_t ctx, char *line)
b5a5d8
 
b5a5d8
   line = skip_options (line);
b5a5d8
   if (!*line)
b5a5d8
-    return set_error (GPG_ERR_ASS_PARAMETER, "no key number given");
b5a5d8
+    {
b5a5d8
+      err = set_error (GPG_ERR_ASS_PARAMETER, "no key number given");
b5a5d8
+      goto leave;
b5a5d8
+    }
b5a5d8
   keyref = line;
b5a5d8
   while (*line && !spacep (line))
b5a5d8
     line++;
b5a5d8
@@ -1448,7 +1451,10 @@ cmd_genkey (assuan_context_t ctx, char *line)
b5a5d8
     goto leave;
b5a5d8
 
b5a5d8
   if (!ctrl->card_ctx)
b5a5d8
-    return gpg_error (GPG_ERR_UNSUPPORTED_OPERATION);
b5a5d8
+    {
b5a5d8
+      err = gpg_error (GPG_ERR_UNSUPPORTED_OPERATION);
b5a5d8
+      goto leave;
b5a5d8
+    }
b5a5d8
 
b5a5d8
   keyref = keyref_buffer = xtrystrdup (keyref);
b5a5d8
   if (!keyref)
b5a5d8
-- 
b5a5d8
2.30.2
b5a5d8
b5a5d8
b5a5d8
From 3b2d9059b95ddb95a9e9fbaceb2f17c8be31d229 Mon Sep 17 00:00:00 2001
b5a5d8
From: Jakub Jelen <jjelen@redhat.com>
b5a5d8
Date: Tue, 13 Apr 2021 14:50:13 +0200
b5a5d8
Subject: [PATCH GnuPG 12/19] tools: Intialize pointer to avoid double free
b5a5d8
b5a5d8
* tools/gpg-card.c (cmd_salut): Initialize data pointer
b5a5d8
b5a5d8
--
b5a5d8
b5a5d8
Signed-off-by: Jakub Jelen <jjelen@redhat.com>
b5a5d8
---
b5a5d8
 tools/gpg-card.c | 1 +
b5a5d8
 1 file changed, 1 insertion(+)
b5a5d8
b5a5d8
diff --git a/tools/gpg-card.c b/tools/gpg-card.c
b5a5d8
index 1889fb45c..e84d2fbb0 100644
b5a5d8
--- a/tools/gpg-card.c
b5a5d8
+++ b/tools/gpg-card.c
b5a5d8
@@ -1785,6 +1785,7 @@ cmd_salut (card_info_t info, const char *argstr)
b5a5d8
         {
b5a5d8
           tty_printf (_("Error: invalid response.\n"));
b5a5d8
           xfree (data);
b5a5d8
+          data = NULL;
b5a5d8
           goto again;
b5a5d8
         }
b5a5d8
     }
b5a5d8
-- 
b5a5d8
2.30.2
b5a5d8
b5a5d8
b5a5d8
From 7c8048b686a6e811d0b24febf3c5e2528e7881f1 Mon Sep 17 00:00:00 2001
b5a5d8
From: Jakub Jelen <jjelen@redhat.com>
b5a5d8
Date: Tue, 13 Apr 2021 16:23:31 +0200
b5a5d8
Subject: [PATCH GnuPG 14/19] dirmgr: Avoid memory leaks
b5a5d8
b5a5d8
* dirmngr/domaininfo.c (insert_or_update): free di_new
b5a5d8
b5a5d8
--
b5a5d8
b5a5d8
Signed-off-by: Jakub Jelen <jjelen@redhat.com>
b5a5d8
---
b5a5d8
 dirmngr/domaininfo.c | 1 +
b5a5d8
 1 file changed, 1 insertion(+)
b5a5d8
b5a5d8
diff --git a/dirmngr/domaininfo.c b/dirmngr/domaininfo.c
b5a5d8
index b41aef366..87782b4b1 100644
b5a5d8
--- a/dirmngr/domaininfo.c
b5a5d8
+++ b/dirmngr/domaininfo.c
b5a5d8
@@ -193,6 +193,7 @@ insert_or_update (const char *domain,
b5a5d8
           log_error ("domaininfo: error allocating helper array: %s\n",
b5a5d8
                      gpg_strerror (gpg_err_code_from_syserror ()));
b5a5d8
           drop_extra = bucket;
b5a5d8
+          xfree (di_new);
b5a5d8
           goto leave;
b5a5d8
         }
b5a5d8
       narray = 0;
b5a5d8
-- 
b5a5d8
2.30.2
b5a5d8
b5a5d8
b5a5d8
From ab3b8c53993b3305088efde756a44bac6e6492d4 Mon Sep 17 00:00:00 2001
b5a5d8
From: Jakub Jelen <jjelen@redhat.com>
b5a5d8
Date: Tue, 13 Apr 2021 16:34:40 +0200
b5a5d8
Subject: [PATCH GnuPG 15/19] scd: Avoid memory leaks and uninitialized memory
b5a5d8
b5a5d8
* scd/app-piv.c (do_decipher): goto leave, initialize outdatalen
b5a5d8
b5a5d8
--
b5a5d8
b5a5d8
Signed-off-by: Jakub Jelen <jjelen@redhat.com>
b5a5d8
---
b5a5d8
 scd/app-piv.c | 4 ++--
b5a5d8
 1 file changed, 2 insertions(+), 2 deletions(-)
b5a5d8
b5a5d8
diff --git a/scd/app-piv.c b/scd/app-piv.c
b5a5d8
index 143cc047a..94257f0ee 100644
b5a5d8
--- a/scd/app-piv.c
b5a5d8
+++ b/scd/app-piv.c
b5a5d8
@@ -2483,7 +2483,7 @@ do_decipher (app_t app, ctrl_t ctrl, const char *keyidstr,
b5a5d8
   gpg_error_t err;
b5a5d8
   data_object_t dobj;
b5a5d8
   unsigned char *outdata = NULL;
b5a5d8
-  size_t outdatalen;
b5a5d8
+  size_t outdatalen = 0;
b5a5d8
   const unsigned char *s;
b5a5d8
   size_t n;
b5a5d8
   int keyref, mechanism;
b5a5d8
@@ -2582,7 +2582,7 @@ do_decipher (app_t app, ctrl_t ctrl, const char *keyidstr,
b5a5d8
   /* Now verify the Application PIN.  */
b5a5d8
   err = verify_chv (app, ctrl, 0x80, 0, pincb, pincb_arg);
b5a5d8
   if (err)
b5a5d8
-    return err;
b5a5d8
+    goto leave;
b5a5d8
 
b5a5d8
   /* Build the Dynamic Authentication Template.  */
b5a5d8
   err = concat_tlv_list (0, &apdudata, &apdudatalen,
b5a5d8
-- 
b5a5d8
2.30.2
b5a5d8
b5a5d8
b5a5d8
From f182bf91443618323e34261039045a6bde269be5 Mon Sep 17 00:00:00 2001
b5a5d8
From: Jakub Jelen <jjelen@redhat.com>
b5a5d8
Date: Tue, 13 Apr 2021 16:44:48 +0200
b5a5d8
Subject: [PATCH GnuPG 16/19] tools: Avoid memory leaks
b5a5d8
b5a5d8
* tools/wks-util.c (wks_cmd_print_wkd_url): Free addrspec on error
b5a5d8
  (wks_cmd_print_wkd_hash): Free addrspec on error
b5a5d8
b5a5d8
--
b5a5d8
b5a5d8
Signed-off-by: Jakub Jelen <jjelen@redhat.com>
b5a5d8
---
b5a5d8
 tools/wks-util.c | 14 ++++++++++----
b5a5d8
 1 file changed, 10 insertions(+), 4 deletions(-)
b5a5d8
b5a5d8
diff --git a/tools/wks-util.c b/tools/wks-util.c
b5a5d8
index 516c7fe00..38dd194ff 100644
b5a5d8
--- a/tools/wks-util.c
b5a5d8
+++ b/tools/wks-util.c
b5a5d8
@@ -1192,11 +1192,14 @@ gpg_error_t
b5a5d8
 wks_cmd_print_wkd_hash (const char *userid)
b5a5d8
 {
b5a5d8
   gpg_error_t err;
b5a5d8
-  char *addrspec, *fname;
b5a5d8
+  char *addrspec = NULL, *fname;
b5a5d8
 
b5a5d8
   err = wks_fname_from_userid (userid, 1, &fname, &addrspec);
b5a5d8
   if (err)
b5a5d8
-    return err;
b5a5d8
+    {
b5a5d8
+      xfree (addrspec);
b5a5d8
+      return err;
b5a5d8
+    }
b5a5d8
 
b5a5d8
   es_printf ("%s %s\n", fname, addrspec);
b5a5d8
 
b5a5d8
@@ -1211,12 +1214,15 @@ gpg_error_t
b5a5d8
 wks_cmd_print_wkd_url (const char *userid)
b5a5d8
 {
b5a5d8
   gpg_error_t err;
b5a5d8
-  char *addrspec, *fname;
b5a5d8
+  char *addrspec = NULL, *fname;
b5a5d8
   char *domain;
b5a5d8
 
b5a5d8
   err = wks_fname_from_userid (userid, 1, &fname, &addrspec);
b5a5d8
   if (err)
b5a5d8
-    return err;
b5a5d8
+    {
b5a5d8
+      xfree (addrspec);
b5a5d8
+      return err;
b5a5d8
+    }
b5a5d8
 
b5a5d8
   domain = strchr (addrspec, '@');
b5a5d8
   if (domain)
b5a5d8
-- 
b5a5d8
2.30.2
b5a5d8
b5a5d8
b5a5d8
From 600fabd8268c765d45d48873e7a8610e6dae0966 Mon Sep 17 00:00:00 2001
b5a5d8
From: Jakub Jelen <jjelen@redhat.com>
b5a5d8
Date: Wed, 14 Apr 2021 15:59:12 +0200
b5a5d8
Subject: [PATCH GnuPG 17/19] scd: Use the same allocator to free memory
b5a5d8
b5a5d8
* scd/command.c (cmd_getinfo): Use free instead of gcry_free to match
b5a5d8
  the original allocator
b5a5d8
b5a5d8
--
b5a5d8
b5a5d8
Signed-off-by: Jakub Jelen <jjelen@redhat.com>
b5a5d8
---
b5a5d8
 scd/command.c | 3 ++-
b5a5d8
 1 file changed, 2 insertions(+), 1 deletion(-)
b5a5d8
b5a5d8
diff --git a/scd/command.c b/scd/command.c
b5a5d8
index cb0dd379a..9d85c5a41 100644
b5a5d8
--- a/scd/command.c
b5a5d8
+++ b/scd/command.c
b5a5d8
@@ -1832,7 +1832,8 @@ cmd_getinfo (assuan_context_t ctx, char *line)
b5a5d8
         rc = assuan_send_data (ctx, p, strlen (p));
b5a5d8
       else
b5a5d8
         rc = gpg_error (GPG_ERR_NO_DATA);
b5a5d8
-      xfree (p);
b5a5d8
+      /* allocated by scd/ccid-driver.c which is not using x*alloc/gcry_* */
b5a5d8
+      free (p);
b5a5d8
     }
b5a5d8
   else if (!strcmp (line, "deny_admin"))
b5a5d8
     rc = opt.allow_admin? gpg_error (GPG_ERR_GENERAL) : 0;
b5a5d8
-- 
b5a5d8
2.30.2
b5a5d8
b5a5d8
b5a5d8
From f45f023495cb9947b2c31b5782a4063ad317c34c Mon Sep 17 00:00:00 2001
b5a5d8
From: Jakub Jelen <jjelen@redhat.com>
b5a5d8
Date: Wed, 14 Apr 2021 18:46:48 +0200
b5a5d8
Subject: [PATCH GnuPG 18/19] common: Mark identical branches as intential
b5a5d8
b5a5d8
* common/tlv-builder.c (get_tlv_length): Mark identical branches as
b5a5d8
  inentional for coverity
b5a5d8
b5a5d8
--
b5a5d8
b5a5d8
Signed-off-by: Jakub Jelen <jjelen@redhat.com>
b5a5d8
---
b5a5d8
 common/tlv-builder.c | 1 +
b5a5d8
 1 file changed, 1 insertion(+)
b5a5d8
b5a5d8
diff --git a/common/tlv-builder.c b/common/tlv-builder.c
b5a5d8
index 3b644ca24..59e2691e0 100644
b5a5d8
--- a/common/tlv-builder.c
b5a5d8
+++ b/common/tlv-builder.c
b5a5d8
@@ -350,6 +350,7 @@ get_tlv_length (int class, int tag, int constructed, size_t length)
b5a5d8
 
b5a5d8
   (void)constructed;  /* Not used, but passed for uniformity of such calls.  */
b5a5d8
 
b5a5d8
+  /* coverity[identical_branches] */
b5a5d8
   if (tag < 0x1f)
b5a5d8
     {
b5a5d8
       buflen++;
b5a5d8
-- 
b5a5d8
2.30.2
b5a5d8
b5a5d8
b5a5d8
From a94b0deab7c2ece2e512f87a52142454354d77b5 Mon Sep 17 00:00:00 2001
b5a5d8
From: Jakub Jelen <jjelen@redhat.com>
b5a5d8
Date: Wed, 14 Apr 2021 18:49:03 +0200
b5a5d8
Subject: [PATCH GnuPG 19/19] g10: Do not allocate memory when we can't return
b5a5d8
 it
b5a5d8
b5a5d8
* g10/keyid.c (fpr20_from_pk): Do not allocate memory when we can't
b5a5d8
  return it
b5a5d8
b5a5d8
--
b5a5d8
b5a5d8
Signed-off-by: Jakub Jelen <jjelen@redhat.com>
b5a5d8
---
b5a5d8
 g10/keyid.c | 2 +-
b5a5d8
 1 file changed, 1 insertion(+), 1 deletion(-)
b5a5d8
b5a5d8
diff --git a/g10/keyid.c b/g10/keyid.c
b5a5d8
index 522cc9cda..f1af2fd90 100644
b5a5d8
--- a/g10/keyid.c
b5a5d8
+++ b/g10/keyid.c
b5a5d8
@@ -899,7 +899,7 @@ fpr20_from_pk (PKT_public_key *pk, byte array[20])
b5a5d8
     compute_fingerprint (pk);
b5a5d8
 
b5a5d8
   if (!array)
b5a5d8
-    array = xmalloc (pk->fprlen);
b5a5d8
+    return;
b5a5d8
 
b5a5d8
   if (pk->fprlen == 32)         /* v5 fingerprint */
b5a5d8
     {
b5a5d8
-- 
b5a5d8
2.30.2
b5a5d8