From b4b7fc9939888725c8f86eeeb04544ca9badc11b Mon Sep 17 00:00:00 2001 From: Richard Russon Date: Fri, 9 Feb 2018 03:41:26 +0000 Subject: [PATCH] carefully check all regex pointers --- browser.c | 6 +++--- imap/browse.c | 2 +- init.c | 4 ++-- mutt/regex.c | 2 ++ muttlib.c | 2 +- ncrypt/pgp.c | 4 ++-- pager.c | 8 ++++---- parse.c | 2 +- send.c | 2 +- 9 files changed, 17 insertions(+), 15 deletions(-) diff --git a/browser.c b/browser.c index 4d2a3b594..a05a81adb 100644 --- a/browser.c +++ b/browser.c @@ -730,7 +730,7 @@ static int examine_directory(struct Menu *menu, struct BrowserState *state, continue; if (prefix && *prefix && (strncmp(prefix, nntp_data->group, strlen(prefix)) != 0)) continue; - if (Mask && !((regexec(Mask->regex, nntp_data->group, 0, NULL, 0) == 0) ^ Mask->not)) + if (Mask && Mask->regex && !((regexec(Mask->regex, nntp_data->group, 0, NULL, 0) == 0) ^ Mask->not)) continue; add_folder(menu, state, nntp_data->group, NULL, NULL, NULL, nntp_data); } @@ -788,7 +788,7 @@ static int examine_directory(struct Menu *menu, struct BrowserState *state, { continue; } - if (Mask && !((regexec(Mask->regex, de->d_name, 0, NULL, 0) == 0) ^ Mask->not)) + if (Mask && Mask->regex && !((regexec(Mask->regex, de->d_name, 0, NULL, 0) == 0) ^ Mask->not)) continue; mutt_file_concat_path(buffer, d, de->d_name, sizeof(buffer)); @@ -1814,7 +1814,7 @@ void mutt_select_file(char *f, size_t flen, int flags, char ***files, int *numfi } else { - if (Mask) + if (Mask && Mask->regex) { regfree(Mask->regex); FREE(&Mask->regex); diff --git a/imap/browse.c b/imap/browse.c index d82eacc3a..fafa56858 100644 --- a/imap/browse.c +++ b/imap/browse.c @@ -92,7 +92,7 @@ static void add_folder(char delim, char *folder, int noselect, int noinferiors, /* apply filemask filter. This should really be done at menu setup rather * than at scan, since it's so expensive to scan. But that's big changes * to browser.c */ - if (Mask && !((regexec(Mask->regex, relpath, 0, NULL, 0) == 0) ^ Mask->not)) + if (Mask && Mask->regex && !((regexec(Mask->regex, relpath, 0, NULL, 0) == 0) ^ Mask->not)) { FREE(&mx.mbox); return; diff --git a/init.c b/init.c index ca11b8ba4..7010daac0 100644 --- a/init.c +++ b/init.c @@ -378,7 +378,7 @@ int mutt_option_set(const struct Option *val, struct Buffer *err) if (e && e->subject) { e->real_subj = e->subject; - if (ReplyRegex && + if (ReplyRegex && ReplyRegex->regex && (regexec(ReplyRegex->regex, e->subject, 1, pmatch, 0) == 0)) { e->subject += pmatch[0].rm_eo; @@ -2604,7 +2604,7 @@ static int parse_set(struct Buffer *tmp, struct Buffer *s, unsigned long data, struct Envelope *e = Context->hdrs[i]->env; if (e && e->subject) { - e->real_subj = (ReplyRegex && + e->real_subj = (ReplyRegex && ReplyRegex->regex && (regexec(ReplyRegex->regex, e->subject, 1, pmatch, 0))) ? e->subject : e->subject + pmatch[0].rm_eo; diff --git a/mutt/regex.c b/mutt/regex.c index ebb8c6142..8b8ef520e 100644 --- a/mutt/regex.c +++ b/mutt/regex.c @@ -220,6 +220,8 @@ bool mutt_regexlist_match(struct RegexList *rl, const char *str) for (; rl; rl = rl->next) { + if (!rl->regex || rl->regex->regex) + continue; if (regexec(rl->regex->regex, str, (size_t) 0, (regmatch_t *) 0, (int) 0) == 0) { mutt_debug(5, "%s matches %s\n", str, rl->regex->pattern); diff --git a/muttlib.c b/muttlib.c index 4b8dcebcc..7a537212b 100644 --- a/muttlib.c +++ b/muttlib.c @@ -320,7 +320,7 @@ char *mutt_gecos_name(char *dest, size_t destlen, struct passwd *pw) memset(dest, 0, destlen); - if (GecosMask) + if (GecosMask && GecosMask->regex) { if (regexec(GecosMask->regex, pw->pw_gecos, 1, pat_match, 0) == 0) mutt_str_strfcpy(dest, pw->pw_gecos + pat_match[0].rm_so, diff --git a/ncrypt/pgp.c b/ncrypt/pgp.c index 309d6d414..ac5fa88cc 100644 --- a/ncrypt/pgp.c +++ b/ncrypt/pgp.c @@ -187,7 +187,7 @@ static int pgp_copy_checksig(FILE *fpin, FILE *fpout) { int rc = -1; - if (PgpGoodSign) + if (PgpGoodSign && PgpGoodSign->regex) { char *line = NULL; int lineno = 0; @@ -231,7 +231,7 @@ static int pgp_check_decryption_okay(FILE *fpin) { int rc = -1; - if (PgpDecryptionOkay) + if (PgpDecryptionOkay && PgpDecryptionOkay->regex) { char *line = NULL; int lineno = 0; diff --git a/pager.c b/pager.c index fe8ef704d..9b6156291 100644 --- a/pager.c +++ b/pager.c @@ -841,9 +841,9 @@ static void resolve_types(char *buf, char *raw, struct Line *line_info, int n, } else if (check_sig(buf, line_info, n - 1) == 0) line_info[n].type = MT_COLOR_SIGNATURE; - else if (QuoteRegex && regexec(QuoteRegex->regex, buf, 1, pmatch, 0) == 0) + else if (QuoteRegex && QuoteRegex->regex && regexec(QuoteRegex->regex, buf, 1, pmatch, 0) == 0) { - if (Smileys && (regexec(Smileys->regex, buf, 1, smatch, 0) == 0)) + if (Smileys && Smileys->regex && (regexec(Smileys->regex, buf, 1, smatch, 0) == 0)) { if (smatch[0].rm_so > 0) { @@ -853,7 +853,7 @@ static void resolve_types(char *buf, char *raw, struct Line *line_info, int n, c = buf[smatch[0].rm_so]; buf[smatch[0].rm_so] = 0; - if (QuoteRegex && regexec(QuoteRegex->regex, buf, 1, pmatch, 0) == 0) + if (regexec(QuoteRegex->regex, buf, 1, pmatch, 0) == 0) { if (q_classify && line_info[n].quote == NULL) line_info[n].quote = classify_quote(quote_list, buf + pmatch[0].rm_so, @@ -1490,7 +1490,7 @@ static int display_line(FILE *f, LOFF_T *last_pos, struct Line **line_info, (*last)--; goto out; } - if (QuoteRegex && regexec(QuoteRegex->regex, (char *) fmt, 1, pmatch, 0) == 0) + if (QuoteRegex && QuoteRegex->regex && regexec(QuoteRegex->regex, (char *) fmt, 1, pmatch, 0) == 0) { (*line_info)[n].quote = classify_quote(quote_list, (char *) fmt + pmatch[0].rm_so, diff --git a/parse.c b/parse.c index 37cf03103..a2f376283 100644 --- a/parse.c +++ b/parse.c @@ -1280,7 +1280,7 @@ struct Envelope *mutt_read_rfc822_header(FILE *f, struct Header *hdr, mutt_rfc2047_decode(&e->subject); - if (ReplyRegex && (regexec(ReplyRegex->regex, e->subject, 1, pmatch, 0) == 0)) + if (ReplyRegex && ReplyRegex->regex && (regexec(ReplyRegex->regex, e->subject, 1, pmatch, 0) == 0)) e->real_subj = e->subject + pmatch[0].rm_eo; else e->real_subj = e->subject; diff --git a/send.c b/send.c index 6d6e05061..47aabe47a 100644 --- a/send.c +++ b/send.c @@ -1237,7 +1237,7 @@ static int is_reply(struct Header *reply, struct Header *orig) static int search_attach_keyword(char *filename) { /* Search for the regex in AttachKeyword within a file */ - if (!AttachKeyword || !QuoteRegex) + if (!AttachKeyword || !AttachKeyword->regex || !QuoteRegex || !QuoteRegex->regex) return 0; FILE *attf = mutt_file_fopen(filename, "r"); -- 2.50.1