mirror of
git://git.gnupg.org/gnupg.git
synced 2025-05-24 16:43:28 +02:00
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@g10code.com>
This commit is contained in:
parent
26c7c1d72c
commit
bd60742925
10
g10/getkey.c
10
g10/getkey.c
@ -1541,7 +1541,7 @@ pubkey_cmp (ctrl_t ctrl, const char *name, struct pubkey_cmp_cookie *old,
|
|||||||
if (! match)
|
if (! match)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
new->uid = uid;
|
new->uid = scopy_user_id (uid);
|
||||||
new->validity =
|
new->validity =
|
||||||
get_validity (ctrl, &new->key, uid, NULL, 0) & TRUST_MASK;
|
get_validity (ctrl, &new->key, uid, NULL, 0) & TRUST_MASK;
|
||||||
new->valid = 1;
|
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. */
|
/* New key is better. */
|
||||||
release_public_key_parts (&best.key);
|
release_public_key_parts (&best.key);
|
||||||
|
if (best.uid)
|
||||||
|
free_user_id (best.uid);
|
||||||
best = new;
|
best = new;
|
||||||
}
|
}
|
||||||
else if (diff > 0)
|
else if (diff > 0)
|
||||||
{
|
{
|
||||||
/* Old key is better. */
|
/* Old key is better. */
|
||||||
release_public_key_parts (&new.key);
|
release_public_key_parts (&new.key);
|
||||||
|
if (new.uid)
|
||||||
|
free_user_id (new.uid);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
/* A tie. Keep the old key. */
|
/* A tie. Keep the old key. */
|
||||||
release_public_key_parts (&new.key);
|
release_public_key_parts (&new.key);
|
||||||
|
if (new.uid)
|
||||||
|
free_user_id (new.uid);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
getkey_end (ctx);
|
getkey_end (ctx);
|
||||||
ctx = NULL;
|
ctx = NULL;
|
||||||
|
if (best.uid)
|
||||||
|
free_user_id (best.uid);
|
||||||
|
|
||||||
if (best.valid)
|
if (best.valid)
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user