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.master
parent
5eb7145939
commit
365058c48f
26
src/rcfile.c
26
src/rcfile.c
|
@ -1064,8 +1064,6 @@ void parse_rule(char *ptr, int rex_flags)
|
||||||
while (*ptr != '\0') {
|
while (*ptr != '\0') {
|
||||||
colortype *newcolor = NULL;
|
colortype *newcolor = NULL;
|
||||||
/* Container for a regex (or regex pair) and the color it paints. */
|
/* 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;
|
bool expectend = FALSE;
|
||||||
/* Whether to expect an end= expression. */
|
/* Whether to expect an end= expression. */
|
||||||
|
|
||||||
|
@ -1080,14 +1078,14 @@ void parse_rule(char *ptr, int rex_flags)
|
||||||
if (ptr == NULL)
|
if (ptr == NULL)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
{
|
newcolor = (colortype *)nmalloc(sizeof(colortype));
|
||||||
newcolor = (colortype *)nmalloc(sizeof(colortype));
|
|
||||||
goodstart = compile(regexstring, rex_flags, &newcolor->start);
|
/* 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->fg = fg;
|
||||||
newcolor->bg = bg;
|
newcolor->bg = bg;
|
||||||
newcolor->attributes = attributes;
|
newcolor->attributes = attributes;
|
||||||
|
@ -1101,8 +1099,6 @@ void parse_rule(char *ptr, int rex_flags)
|
||||||
lastcolor->next = newcolor;
|
lastcolor->next = newcolor;
|
||||||
|
|
||||||
lastcolor = newcolor;
|
lastcolor = newcolor;
|
||||||
} else
|
|
||||||
free(newcolor);
|
|
||||||
|
|
||||||
if (!expectend)
|
if (!expectend)
|
||||||
continue;
|
continue;
|
||||||
|
@ -1118,12 +1114,12 @@ void parse_rule(char *ptr, int rex_flags)
|
||||||
if (ptr == NULL)
|
if (ptr == NULL)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
/* If the start regex was invalid, the end regex cannot be saved. */
|
/* When the end= regex is invalid, abandon the whole rule. */
|
||||||
if (!goodstart)
|
if (!compile(regexstring, rex_flags, &newcolor->end)) {
|
||||||
|
regfree(newcolor->start);
|
||||||
|
free(newcolor);
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
/* Save the compiled ending regex (when it's valid). */
|
|
||||||
compile(regexstring, rex_flags, &newcolor->end);
|
|
||||||
|
|
||||||
/* Lame way to skip another static counter. */
|
/* Lame way to skip another static counter. */
|
||||||
newcolor->id = live_syntax->nmultis;
|
newcolor->id = live_syntax->nmultis;
|
||||||
|
|
Loading…
Reference in New Issue