From 47e6c5aac5200582600cc0823191bb3bc7799daf Mon Sep 17 00:00:00 2001 From: Kevin McCarthy Date: Thu, 22 Mar 2018 20:04:46 -0700 Subject: [PATCH] Fix comparison of flags with multiple bits set. PGPENCRYPT, PGPKEY, SMIMEENCRYPT, and SMIMEOPAQUE are all combination flags, with multiple bits set. In a few places these flags were bitwise-and'ed incorrectly: expecting a non-zero result to indicate all the bits in the flag were set. Change those to explicitly compare the result against the original flag. --- hdrline.c | 3 ++- pattern.c | 2 +- recvattach.c | 2 +- sendlib.c | 8 ++++---- 4 files changed, 8 insertions(+), 7 deletions(-) diff --git a/hdrline.c b/hdrline.c index ba118bf5..ea76e836 100644 --- a/hdrline.c +++ b/hdrline.c @@ -688,7 +688,8 @@ hdr_format_str (char *dest, ch = 'P'; else if (WithCrypto && hdr->security & SIGN) ch = 's'; - else if ((WithCrypto & APPLICATION_PGP) && hdr->security & PGPKEY) + else if ((WithCrypto & APPLICATION_PGP) && + ((hdr->security & PGPKEY) == PGPKEY)) ch = 'K'; snprintf (buf2, sizeof (buf2), diff --git a/pattern.c b/pattern.c index d71252f2..285cbfa6 100644 --- a/pattern.c +++ b/pattern.c @@ -1323,7 +1323,7 @@ mutt_pattern_exec (struct pattern_t *pat, pattern_exec_flag flags, CONTEXT *ctx, case MUTT_PGP_KEY: if (!(WithCrypto & APPLICATION_PGP)) break; - return (pat->not ^ ((h->security & APPLICATION_PGP) && (h->security & PGPKEY))); + return (pat->not ^ ((h->security & PGPKEY) == PGPKEY)); case MUTT_XLABEL: return (pat->not ^ (h->env->x_label && patmatch (pat, h->env->x_label) == 0)); case MUTT_HORMEL: diff --git a/recvattach.c b/recvattach.c index 07c4ba8c..768e1d6f 100644 --- a/recvattach.c +++ b/recvattach.c @@ -955,7 +955,7 @@ static void mutt_generate_recvattach_list (ATTACH_CONTEXT *actx, secured = !crypt_smime_decrypt_mime (fp, &new_fp, m, &new_body); /* S/MIME nesting */ - if ((mutt_is_application_smime (new_body) & SMIMEOPAQUE)) + if ((mutt_is_application_smime (new_body) & SMIMEOPAQUE) == SMIMEOPAQUE) { BODY *outer_new_body = new_body; FILE *outer_fp = new_fp; diff --git a/sendlib.c b/sendlib.c index da1e5053..ef428541 100644 --- a/sendlib.c +++ b/sendlib.c @@ -1321,15 +1321,15 @@ BODY *mutt_make_message_attach (CONTEXT *ctx, HEADER *hdr, int attach_msg) cmflags = MUTT_CM_DECODE_PGP; pgp &= ~PGPENCRYPT; } - else if ((WithCrypto & APPLICATION_PGP) - && (mutt_is_application_pgp (hdr->content) & PGPENCRYPT)) + else if ((WithCrypto & APPLICATION_PGP) && + ((mutt_is_application_pgp (hdr->content) & PGPENCRYPT) == PGPENCRYPT)) { chflags |= CH_MIME | CH_TXTPLAIN; cmflags = MUTT_CM_DECODE | MUTT_CM_CHARCONV; pgp &= ~PGPENCRYPT; } - else if ((WithCrypto & APPLICATION_SMIME) - && mutt_is_application_smime (hdr->content) & SMIMEENCRYPT) + else if ((WithCrypto & APPLICATION_SMIME) && + ((mutt_is_application_smime (hdr->content) & SMIMEENCRYPT) == SMIMEENCRYPT)) { chflags |= CH_MIME | CH_TXTPLAIN; cmflags = MUTT_CM_DECODE | MUTT_CM_CHARCONV; -- 2.40.0