From 5eb71459395c31eefc2e0dffd803b5b991d1b13e Mon Sep 17 00:00:00 2001 From: Benno Schulenberg Date: Tue, 3 Mar 2020 17:37:13 +0100 Subject: [PATCH] rcfile: do not allow a regex for name, header, or magic to be empty If the user really wants to match anything, ".*" should be used. (This also stops nano looking at the rest of the line as soon as an empty regular expression is encountered. This may seem like poorer feedback than before, but... I think that multiple error messages per line are more confusing than helpful.) This fixes https://savannah.gnu.org/bugs/?57942. Bug existed since before version 2.2.0. --- src/rcfile.c | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/src/rcfile.c b/src/rcfile.c index 23b3275d..ee5d49cc 100644 --- a/src/rcfile.c +++ b/src/rcfile.c @@ -557,6 +557,8 @@ char *parse_argument(char *ptr) * null-terminate it, and return a pointer to the succeeding text. */ char *parse_next_regex(char *ptr) { + char *starting_point = ptr; + if (*(ptr - 1) != '"') { jot_error(N_("Regex strings must begin and end with a \" character")); return NULL; @@ -573,6 +575,11 @@ char *parse_next_regex(char *ptr) return NULL; } + if (ptr == starting_point) { + jot_error(N_("Empty regex string")); + return NULL; + } + /* Null-terminate the regex and skip until the next non-blank. */ *ptr++ = '\0'; @@ -1073,10 +1080,7 @@ void parse_rule(char *ptr, int rex_flags) if (ptr == NULL) return; - if (*regexstring == '\0') { - jot_error(N_("Empty regex string")); - goodstart = FALSE; - } else { + { newcolor = (colortype *)nmalloc(sizeof(colortype)); goodstart = compile(regexstring, rex_flags, &newcolor->start); } @@ -1114,11 +1118,6 @@ void parse_rule(char *ptr, int rex_flags) if (ptr == NULL) return; - if (*regexstring == '\0') { - jot_error(N_("Empty regex string")); - return; - } - /* If the start regex was invalid, the end regex cannot be saved. */ if (!goodstart) return;