--- lib/string.c | 12 ++++++++++++ lib/string2.h | 1 + ncrypt/crypt_gpgme.c | 2 +- ncrypt/pgp.c | 24 ++++++++++++------------ pager.c | 2 +- 5 files changed, 27 insertions(+), 14 deletions(-) --- lib/string.c +++ lib/string.c 2017-09-11 12:12:00.503744275 +0000 @@ -362,6 +362,18 @@ int mutt_strcmp(const char *a, const cha return strcmp(NONULL(a), NONULL(b)); } +int mutt_strxcmp(const char *a, const char *b) +{ + size_t xa, xb; + xa = strcspn(NONULL(a), "\r\n"); + xb = strcspn(NONULL(b), "\r\n"); + if (xb != xa) + return -1; + if (!xa) + return 0; + return strncmp(NONULL(a), NONULL(b), xa); +} + /** * mutt_strcasecmp - Compare two strings ignoring case, safely * @param a First string to compare --- lib/string2.h +++ lib/string2.h 2017-09-11 12:14:01.681538993 +0000 @@ -67,6 +67,7 @@ void mutt_str_adjust(char **p); int mutt_strcasecmp(const char *a, const char *b); const char *mutt_strchrnul(const char *s, char c); int mutt_strcmp(const char *a, const char *b); +int mutt_strxcmp(const char *a, const char *b); int mutt_strcoll(const char *a, const char *b); const char *mutt_stristr(const char *haystack, const char *needle); size_t mutt_strlen(const char *a); --- ncrypt/crypt_gpgme.c +++ ncrypt/crypt_gpgme.c 2017-09-11 12:09:17.086717319 +0000 @@ -2442,7 +2442,7 @@ static void copy_clearsigned(gpgme_data_ if (armor_header) { - if (buf[0] == '\n') + if (buf[0] == '\n' || (buf[0] == '\r' && buf[1] == '\n')) armor_header = false; continue; } --- ncrypt/pgp.c +++ ncrypt/pgp.c 2017-09-11 12:08:10.179934232 +0000 @@ -301,7 +301,7 @@ static void pgp_copy_clearsigned(FILE *f continue; } - if (mutt_strcmp(buf, "-----BEGIN PGP SIGNATURE-----\n") == 0) + if (mutt_strxcmp(buf, "-----BEGIN PGP SIGNATURE-----\n") == 0) break; if (armor_header) @@ -369,14 +369,14 @@ int pgp_application_pgp_handler(struct B { clearsign = false; - if (mutt_strcmp("MESSAGE-----\n", buf + 15) == 0) + if (mutt_strxcmp("MESSAGE-----\n", buf + 15) == 0) needpass = 1; - else if (mutt_strcmp("SIGNED MESSAGE-----\n", buf + 15) == 0) + else if (mutt_strxcmp("SIGNED MESSAGE-----\n", buf + 15) == 0) { clearsign = true; needpass = 0; } - else if (mutt_strcmp("PUBLIC KEY BLOCK-----\n", buf + 15) == 0) + else if (mutt_strxcmp("PUBLIC KEY BLOCK-----\n", buf + 15) == 0) { needpass = 0; pgp_keyblock = true; @@ -410,9 +410,9 @@ int pgp_application_pgp_handler(struct B fputs(buf, tmpfp); - if ((needpass && (mutt_strcmp("-----END PGP MESSAGE-----\n", buf) == 0)) || - (!needpass && ((mutt_strcmp("-----END PGP SIGNATURE-----\n", buf) == 0) || - (mutt_strcmp("-----END PGP PUBLIC KEY BLOCK-----\n", buf) == 0)))) + if ((needpass && (mutt_strxcmp("-----END PGP MESSAGE-----\n", buf) == 0)) || + (!needpass && ((mutt_strxcmp("-----END PGP SIGNATURE-----\n", buf) == 0) || + (mutt_strxcmp("-----END PGP PUBLIC KEY BLOCK-----\n", buf) == 0)))) break; /* remember optional Charset: armor header as defined by RfC4880 */ if (mutt_strncmp("Charset: ", buf, 9) == 0) @@ -650,11 +650,11 @@ static int pgp_check_traditional_one_bod { if (mutt_strncmp("-----BEGIN PGP ", buf, 15) == 0) { - if (mutt_strcmp("MESSAGE-----\n", buf + 15) == 0) + if (mutt_strxcmp("MESSAGE-----\n", buf + 15) == 0) enc = 1; - else if (mutt_strcmp("SIGNED MESSAGE-----\n", buf + 15) == 0) + else if (mutt_strxcmp("SIGNED MESSAGE-----\n", buf + 15) == 0) sgn = 1; - else if (mutt_strcmp("PUBLIC KEY BLOCK-----\n", buf + 15) == 0) + else if (mutt_strxcmp("PUBLIC KEY BLOCK-----\n", buf + 15) == 0) key = 1; } } @@ -1144,9 +1144,9 @@ struct Body *pgp_sign_message(struct Bod */ while (fgets(buffer, sizeof(buffer) - 1, pgpout) != NULL) { - if (mutt_strcmp("-----BEGIN PGP MESSAGE-----\n", buffer) == 0) + if (mutt_strxcmp("-----BEGIN PGP MESSAGE-----\n", buffer) == 0) fputs("-----BEGIN PGP SIGNATURE-----\n", fp); - else if (mutt_strcmp("-----END PGP MESSAGE-----\n", buffer) == 0) + else if (mutt_strxcmp("-----END PGP MESSAGE-----\n", buffer) == 0) fputs("-----END PGP SIGNATURE-----\n", fp); else fputs(buffer, fp); --- pager.c +++ pager.c 2017-09-11 12:10:06.737814133 +0000 @@ -827,7 +827,7 @@ static void resolve_types(char *buf, cha line_info[n].type = MT_COLOR_NORMAL; else if (check_attachment_marker((char *) raw) == 0) line_info[n].type = MT_COLOR_ATTACHMENT; - else if ((mutt_strcmp("-- \n", buf) == 0) || (mutt_strcmp("-- \r\n", buf) == 0)) + else if (mutt_strxcmp("-- \n", buf) == 0) { i = n + 1;