Skip to content

Commit

Permalink
Fix use after free of a->mailbox due to missing strdup
Browse files Browse the repository at this point in the history
Commit 87ae932 ("Directly add full mailbox to
GPG search hints") changed crypt_add_string_to_hints(a->mailbox, &hints) to
mutt_list_insert_tail(&hints, a->mailbox). However, there is a behavioural
difference between the two functions: crypt_add_string_to_hints() adds a copy
of the string to the list, while mutt_list_insert_tail() does not. This leads
to a crash because the original a->mailbox is freed prematurely as part of the
hints list. Fix this by adding a copy of the original to the list instead.

Note that commit 87ae932 originally came from
Mutt. Upstream is not affected by this however because their mutt_add_list()
functions always copies the data.
  • Loading branch information
diabonas authored and flatcap committed Oct 23, 2021
1 parent e9f3170 commit a4a02a4
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion ncrypt/crypt_gpgme.c
Expand Up @@ -3581,7 +3581,7 @@ static struct CryptKeyInfo *crypt_getkeybyaddr(struct Address *a,
*forced_valid = 0;

if (a && a->mailbox)
mutt_list_insert_tail(&hints, a->mailbox);
mutt_list_insert_tail(&hints, mutt_str_dup(a->mailbox));
if (a && a->personal)
crypt_add_string_to_hints(a->personal, &hints);

Expand Down
2 changes: 1 addition & 1 deletion ncrypt/pgpkey.c
Expand Up @@ -369,7 +369,7 @@ struct PgpKeyInfo *pgp_getkeybyaddr(struct Address *a, KeyFlags abilities,
struct PgpUid *q = NULL;

if (a->mailbox)
mutt_list_insert_tail(&hints, a->mailbox);
mutt_list_insert_tail(&hints, mutt_str_dup(a->mailbox));
if (a->personal)
pgp_add_string_to_hints(a->personal, &hints);

Expand Down

0 comments on commit a4a02a4

Please sign in to comment.