rcfile: disallow 'bind' and 'unbind' in an included file

Included files are meant to contain only syntax definitions; they may
not set or unset options, nor rebind keys, nor include other files.

This fixes https://savannah.gnu.org/bugs/?47391.
master
Benno Schulenberg 2016-04-27 10:07:45 +02:00
parent 30f3c53305
commit 9330aa60a5
1 changed files with 11 additions and 26 deletions

View File

@ -967,34 +967,9 @@ void parse_rcfile(FILE *rcstream
keyword = ptr; keyword = ptr;
ptr = parse_next_word(ptr); ptr = parse_next_word(ptr);
} }
#endif
/* Try to parse the keyword. */ /* Try to parse the keyword. */
if (strcasecmp(keyword, "set") == 0) { if (strcasecmp(keyword, "syntax") == 0) {
#ifndef DISABLE_COLOR
if (syntax_only)
rcfile_error(N_("Command \"%s\" not allowed in included file"),
keyword);
else
#endif
set = 1;
} else if (strcasecmp(keyword, "unset") == 0) {
#ifndef DISABLE_COLOR
if (syntax_only)
rcfile_error(N_("Command \"%s\" not allowed in included file"),
keyword);
else
#endif
set = -1;
}
#ifndef DISABLE_COLOR
else if (strcasecmp(keyword, "include") == 0) {
if (syntax_only)
rcfile_error(N_("Command \"%s\" not allowed in included file"),
keyword);
else
parse_includes(ptr);
} else if (strcasecmp(keyword, "syntax") == 0) {
if (opensyntax && lastcolor == NULL) if (opensyntax && lastcolor == NULL)
rcfile_error(N_("Syntax \"%s\" has no color commands"), rcfile_error(N_("Syntax \"%s\" has no color commands"),
live_syntax->name); live_syntax->name);
@ -1020,7 +995,17 @@ void parse_rcfile(FILE *rcstream
#else #else
; ;
#endif #endif
else if (syntax_only)
rcfile_error(N_("Command \"%s\" not allowed in included file"),
keyword);
else if (strcasecmp(keyword, "include") == 0)
parse_includes(ptr);
else
#endif /* !DISABLE_COLOR */ #endif /* !DISABLE_COLOR */
if (strcasecmp(keyword, "set") == 0)
set = 1;
else if (strcasecmp(keyword, "unset") == 0)
set = -1;
else if (strcasecmp(keyword, "bind") == 0) else if (strcasecmp(keyword, "bind") == 0)
parse_binding(ptr, TRUE); parse_binding(ptr, TRUE);
else if (strcasecmp(keyword, "unbind") == 0) else if (strcasecmp(keyword, "unbind") == 0)