commit 365058c48f94696cdf4023d1bdd14ce5f6d2e8b3
parent 5eb71459395c31eefc2e0dffd803b5b991d1b13e
Author: Benno Schulenberg <bensberg@telfort.nl>
Date: Tue, 3 Mar 2020 19:42:40 +0100
rcfile: when a start= is not matched with an end=, abandon the whole rule
This fixes https://savannah.gnu.org/bugs/?57950.
Bug existed since before version 2.2.0.
Diffstat:
1 file changed, 11 insertions(+), 15 deletions(-)
diff --git a/src/rcfile.c b/src/rcfile.c
@@ -1064,8 +1064,6 @@ void parse_rule(char *ptr, int rex_flags)
while (*ptr != '\0') {
colortype *newcolor = NULL;
/* Container for a regex (or regex pair) and the color it paints. */
- bool goodstart;
- /* Whether the expression or start= expression was valid. */
bool expectend = FALSE;
/* Whether to expect an end= expression. */
@@ -1080,14 +1078,14 @@ void parse_rule(char *ptr, int rex_flags)
if (ptr == NULL)
return;
- {
- newcolor = (colortype *)nmalloc(sizeof(colortype));
- goodstart = compile(regexstring, rex_flags, &newcolor->start);
+ newcolor = (colortype *)nmalloc(sizeof(colortype));
+
+ /* When the regex is invalid, abandon the rule. */
+ if (!compile(regexstring, rex_flags, &newcolor->start)) {
+ free(newcolor);
+ return;
}
- /* If the start regex is valid, fill in the rest of the data, and
- * hook the new color struct in at the tail of the linked list. */
- if (goodstart) {
newcolor->fg = fg;
newcolor->bg = bg;
newcolor->attributes = attributes;
@@ -1101,8 +1099,6 @@ void parse_rule(char *ptr, int rex_flags)
lastcolor->next = newcolor;
lastcolor = newcolor;
- } else
- free(newcolor);
if (!expectend)
continue;
@@ -1118,12 +1114,12 @@ void parse_rule(char *ptr, int rex_flags)
if (ptr == NULL)
return;
- /* If the start regex was invalid, the end regex cannot be saved. */
- if (!goodstart)
+ /* When the end= regex is invalid, abandon the whole rule. */
+ if (!compile(regexstring, rex_flags, &newcolor->end)) {
+ regfree(newcolor->start);
+ free(newcolor);
return;
-
- /* Save the compiled ending regex (when it's valid). */
- compile(regexstring, rex_flags, &newcolor->end);
+ }
/* Lame way to skip another static counter. */
newcolor->id = live_syntax->nmultis;