From c2aa0c0643a483bb5305180a7a388264245e8f8a Mon Sep 17 00:00:00 2001 From: Pietro Cerutti Date: Fri, 9 Nov 2018 15:44:06 +0000 Subject: [PATCH] mutt_str_startswith - ncrypt/pgp.c --- ncrypt/pgp.c | 35 +++++++++++++++++++---------------- 1 file changed, 19 insertions(+), 16 deletions(-) diff --git a/ncrypt/pgp.c b/ncrypt/pgp.c index b362bba40..7cc6ac07f 100644 --- a/ncrypt/pgp.c +++ b/ncrypt/pgp.c @@ -361,15 +361,16 @@ static int pgp_check_decryption_okay(FILE *fpin) while ((line = mutt_file_read_line(line, &linelen, fpin, &lineno, 0))) { - if (mutt_str_strncmp(line, "[GNUPG:] ", 9) != 0) + size_t plen = mutt_str_startswith(line, "[GNUPG:]", CASE_MATCH); + if (plen == 0) continue; - s = line + 9; + s = line + plen; mutt_debug(2, "checking \"%s\".\n", line); - if (mutt_str_strncmp(s, "BEGIN_DECRYPTION", 16) == 0) + if (mutt_str_startswith(s, "BEGIN_DECRYPTION", CASE_MATCH)) inside_decrypt = 1; - else if (mutt_str_strncmp(s, "END_DECRYPTION", 14) == 0) + else if (mutt_str_startswith(s, "END_DECRYPTION", CASE_MATCH)) inside_decrypt = 0; - else if (mutt_str_strncmp(s, "PLAINTEXT", 9) == 0) + else if (mutt_str_startswith(s, "PLAINTEXT", CASE_MATCH)) { if (!inside_decrypt) { @@ -379,13 +380,13 @@ static int pgp_check_decryption_okay(FILE *fpin) break; } } - else if (mutt_str_strncmp(s, "DECRYPTION_FAILED", 17) == 0) + else if (mutt_str_startswith(s, "DECRYPTION_FAILED", CASE_MATCH)) { mutt_debug(2, "\tDECRYPTION_FAILED encountered. Failure.\n"); rv = -3; break; } - else if (mutt_str_strncmp(s, "DECRYPTION_OKAY", 15) == 0) + else if (mutt_str_startswith(s, "DECRYPTION_OKAY", CASE_MATCH)) { /* Don't break out because we still have to check for * PLAINTEXT outside of the decryption boundaries. */ @@ -499,20 +500,21 @@ int pgp_class_application_handler(struct Body *m, struct State *s) bytes -= (offset - last_pos); /* don't rely on mutt_str_strlen(buf) */ last_pos = offset; - if (mutt_str_strncmp("-----BEGIN PGP ", buf, 15) == 0) + size_t plen = mutt_str_startswith(buf, "-----BEGIN PGP ", CASE_MATCH); + if (plen != 0) { clearsign = false; could_not_decrypt = false; decrypt_okay_rc = 0; - if (mutt_str_strcmp("MESSAGE-----\n", buf + 15) == 0) + if (mutt_str_startswith(buf + plen, "MESSAGE-----\n", CASE_MATCH)) needpass = 1; - else if (mutt_str_strcmp("SIGNED MESSAGE-----\n", buf + 15) == 0) + else if (mutt_str_startswith(buf + plen, "SIGNED MESSAGE-----\n", CASE_MATCH)) { clearsign = true; needpass = 0; } - else if (mutt_str_strcmp("PUBLIC KEY BLOCK-----\n", buf + 15) == 0) + else if (mutt_str_startswith(buf + plen, "PUBLIC KEY BLOCK-----\n", CASE_MATCH)) { needpass = 0; pgp_keyblock = true; @@ -555,7 +557,7 @@ int pgp_class_application_handler(struct Body *m, struct State *s) break; } /* remember optional Charset: armor header as defined by RFC4880 */ - if (mutt_str_strncmp("Charset: ", buf, 9) == 0) + if (mutt_str_startswith(buf, "Charset: ", CASE_MATCH)) { size_t l = 0; FREE(&gpgcharset); @@ -806,13 +808,14 @@ static int pgp_check_traditional_one_body(FILE *fp, struct Body *b) while (fgets(buf, sizeof(buf), tfp)) { - if (mutt_str_strncmp("-----BEGIN PGP ", buf, 15) == 0) + size_t plen = mutt_str_startswith(buf, "-----BEGIN PGP ", CASE_MATCH); + if (plen != 0) { - if (mutt_str_strcmp("MESSAGE-----\n", buf + 15) == 0) + if (mutt_str_startswith(buf + plen, "MESSAGE-----\n", CASE_MATCH)) enc = true; - else if (mutt_str_strcmp("SIGNED MESSAGE-----\n", buf + 15) == 0) + else if (mutt_str_startswith(buf + plen, "SIGNED MESSAGE-----\n", CASE_MATCH)) sgn = true; - else if (mutt_str_strcmp("PUBLIC KEY BLOCK-----\n", buf + 15) == 0) + else if (mutt_str_startswith(buf + plen, "PUBLIC KEY BLOCK-----\n", CASE_MATCH)) key = true; } } -- 2.49.0