From 6705a39bd390ce9d53536c16ecd160ec1a0ecd2c Mon Sep 17 00:00:00 2001 From: Werner Fink Date: Tue, 30 May 2017 12:52:12 +0000 Subject: [PATCH] Fix crash if no from is set or founds On multi folder mailbox setup and without a set 'From:' line in ~/.muttrc the mutt crash with SIGSEGV on a NULL pointer at msg->env->from Fixes: #577 --- ncrypt/crypt.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/ncrypt/crypt.c b/ncrypt/crypt.c index 0b5aa8368..6da482141 100644 --- a/ncrypt/crypt.c +++ b/ncrypt/crypt.c @@ -181,11 +181,20 @@ int mutt_protect(struct Header *msg, char *keylist) if (option(OPTCRYPTUSEPKA) && (msg->security & SIGN)) { /* Set sender (necessary for e.g. PKA). */ + const char *mailbox = NULL; + const struct Address *from = msg->env->from; + + if (!from) + from = mutt_default_from(); + + mailbox = from->mailbox; + if (!mailbox && EnvFrom) + mailbox = EnvFrom->mailbox; if ((WithCrypto & APPLICATION_SMIME) && (msg->security & APPLICATION_SMIME)) - crypt_smime_set_sender(msg->env->from->mailbox); + crypt_smime_set_sender(mailbox); else if ((WithCrypto & APPLICATION_PGP) && (msg->security & APPLICATION_PGP)) - crypt_pgp_set_sender(msg->env->from->mailbox); + crypt_pgp_set_sender(mailbox); } if (msg->security & SIGN) -- 2.40.0