g10: Fix double free when locating by mbox
authorAndre Heinecke <aheinecke@intevation.de>
Thu, 18 Apr 2019 11:19:05 +0000 (13:19 +0200)
committerDaniel Kahn Gillmor <dkg@fifthhorseman.net>
Fri, 1 Jul 2022 16:06:43 +0000 (17:06 +0100)
commit3c92c309fbf8bf0dfe0746e09917c56567f19b1e
tree437db9ea54df9ae06832a7948afb81dfd9beadb8
parent719945c05bd3c2ba19c490bf1341ae24c8b7be77
g10: Fix double free when locating by mbox

* g10/getkey.c (get_best_pubkey_byname): Set new.uid always
to NULL after use.

--
pubkey_cmp is not guranteed to set new.uid.
So if the diff < 0 case is reached best is set to new.

If then diff > 0 is reached without modifying new.uid
e.g. if the key has no matching mboxes. new.uid is
free'd even though the uid is still referenced in
best.

GnuPG-Bug-Id: T4462
(cherry picked from commit e57954ed278cb5e6e725005b1ecaf7ce70006ce0)
(cherry picked from commit 35899dc2903b118620e6f9f0fa6b21c8568abbf1)

Gbp-Pq: Topic from-2.2.16
Gbp-Pq: Name g10-Fix-double-free-when-locating-by-mbox.patch
g10/getkey.c