1
0
Fork 0
mirror of git://git.gnupg.org/gnupg.git synced 2025-07-03 22:56:33 +02:00

agent: Fix memory leaks

* agent/call-daemon.c (daemon_start): free wctp
* agent/call-scd.c (agent_card_pksign): return error instead of noop
(card_keyinfo_cb): free keyinfo.  Restructure to avoid a goto backwards.
* agent/protect.c (agent_get_shadow_info_type): allocate only as a last
action.  Catch xtrymalloc failure.
(agent_is_tpm2_key): Free buf.

--

Signed-off-by: Jakub Jelen <jjelen@redhat.com>

Additional changes are:
- Restructure to avoid a goto backwards.
- Catch xtrymalloc failure.

GnuPG-bug-id: 5393
Signed-off-by: Werner Koch <wk@gnupg.org>
This commit is contained in:
Jakub Jelen 2021-04-12 19:19:59 +02:00 committed by Werner Koch
parent e6132bc9f4
commit 33a2362e56
No known key found for this signature in database
GPG key ID: E3FDFF218E45B72B
3 changed files with 30 additions and 22 deletions

View file

@ -1660,13 +1660,6 @@ agent_get_shadow_info_type (const unsigned char *shadowkey,
n = snext (&s);
if (!n)
return gpg_error (GPG_ERR_INV_SEXP);
if (shadow_type) {
char *buf = xtrymalloc(n+1);
memcpy(buf, s, n);
buf[n] = '\0';
*shadow_type = buf;
}
if (smatch (&s, n, "t1-v1") || smatch(&s, n, "tpm2-v1"))
{
if (*s != '(')
@ -1676,6 +1669,17 @@ agent_get_shadow_info_type (const unsigned char *shadowkey,
}
else
return gpg_error (GPG_ERR_UNSUPPORTED_PROTOCOL);
if (shadow_type)
{
char *buf = xtrymalloc(n+1);
if (!buf)
return gpg_error_from_syserror ();
memcpy (buf, s, n);
buf[n] = '\0';
*shadow_type = buf;
}
return 0;
}
@ -1701,9 +1705,9 @@ agent_is_tpm2_key (gcry_sexp_t s_skey)
return 0;
err = agent_get_shadow_info_type (buf, NULL, &type);
xfree (buf);
if (err)
return 0;
xfree (buf);
err = strcmp (type, "tpm2-v1") == 0;
xfree (type);