From: Kevin McCarthy Date: Fri, 23 Mar 2018 03:04:46 +0000 (-0700) Subject: Fix comparison of flags with multiple bits set. X-Git-Tag: neomutt-20180512~84^2~1 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=bf9ce16b2ef9d36b3a3968b9c55ef469437167c6;p=neomutt 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. --- diff --git a/hdrline.c b/hdrline.c index fd0bb77da..4e77975d7 100644 --- a/hdrline.c +++ b/hdrline.c @@ -1250,7 +1250,7 @@ static const char *index_format_str(char *buf, size_t buflen, size_t col, int co ch = "P"; else if ((WithCrypto != 0) && (hdr->security & SIGN)) ch = "s"; - else if (((WithCrypto & APPLICATION_PGP) != 0) && (hdr->security & PGPKEY)) + else if (((WithCrypto & APPLICATION_PGP) != 0) && ((hdr->security & PGPKEY) == PGPKEY)) ch = "K"; else ch = " "; diff --git a/pattern.c b/pattern.c index 28b1f82eb..6a49d03f3 100644 --- a/pattern.c +++ b/pattern.c @@ -1710,7 +1710,7 @@ int mutt_pattern_exec(struct Pattern *pat, enum PatternExecFlag flags, 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: if (!h->env) return 0; diff --git a/recvattach.c b/recvattach.c index 38b48f1dd..404033375 100644 --- a/recvattach.c +++ b/recvattach.c @@ -997,7 +997,7 @@ static void mutt_generate_recvattach_list(struct AttachCtx *actx, struct Header 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) { struct Body *outer_new_body = new_body; FILE *outer_fp = new_fp; diff --git a/sendlib.c b/sendlib.c index 6c7ed46c4..abb6982ba 100644 --- a/sendlib.c +++ b/sendlib.c @@ -1395,14 +1395,14 @@ struct Body *mutt_make_message_attach(struct Context *ctx, struct Header *hdr, i pgp &= ~PGPENCRYPT; } else if (((WithCrypto & APPLICATION_PGP) != 0) && - (mutt_is_application_pgp(hdr->content) & PGPENCRYPT)) + ((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) != 0) && - mutt_is_application_smime(hdr->content) & SMIMEENCRYPT) + ((mutt_is_application_smime(hdr->content) & SMIMEENCRYPT) == SMIMEENCRYPT)) { chflags |= CH_MIME | CH_TXTPLAIN; cmflags = MUTT_CM_DECODE | MUTT_CM_CHARCONV;