Disallowing the addition of further things to a syntax when

an rcfile ends or when an invalid syntax command is found.
This fixes Savannah bug #47207


git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@5696 35c25a1d-7b9e-4130-9fde-d3aeb78583b8
This commit is contained in:
Benno Schulenberg 2016-02-28 20:38:14 +00:00
parent 68d94a0c74
commit 275e9f0092
2 changed files with 17 additions and 4 deletions

View File

@ -8,6 +8,9 @@
* src/rcfile.c (grab_and_store): Do not drop regexes that were * src/rcfile.c (grab_and_store): Do not drop regexes that were
gathered earlier. This fixes Savannah bug #47285. gathered earlier. This fixes Savannah bug #47285.
* src/rcfile.c (grab_and_store): Rearrange things in my style. * src/rcfile.c (grab_and_store): Rearrange things in my style.
* src/rcfile.c (parse_syntax, parse_rcfile): Disallow adding any
further things to a syntax when an rcfile ends or when an invalid
syntax command is found. This fixes Savannah bug #47207.
2016-02-26 Benno Schulenberg <bensberg@justemail.net> 2016-02-26 Benno Schulenberg <bensberg@justemail.net>
* doc/man/nanorc.5, doc/texinfo/nano.texi, doc/syntax/nanorc.nanorc, * doc/man/nanorc.5, doc/texinfo/nano.texi, doc/syntax/nanorc.nanorc,

View File

@ -120,6 +120,9 @@ static size_t lineno = 0;
static char *nanorc = NULL; static char *nanorc = NULL;
/* The path to the rcfile we're parsing. */ /* The path to the rcfile we're parsing. */
#ifndef DISABLE_COLOR #ifndef DISABLE_COLOR
static bool opensyntax = FALSE;
/* Whether we're allowed to add to the last syntax. When a file ends,
* or when a new syntax command is seen, this bool becomes FALSE. */
static syntaxtype *endsyntax = NULL; static syntaxtype *endsyntax = NULL;
/* The end of the list of syntaxes. */ /* The end of the list of syntaxes. */
static colortype *endcolor = NULL; static colortype *endcolor = NULL;
@ -268,6 +271,8 @@ void parse_syntax(char *ptr)
regexlisttype *endext = NULL; regexlisttype *endext = NULL;
/* The end of the extensions list for this syntax. */ /* The end of the extensions list for this syntax. */
opensyntax = FALSE;
assert(ptr != NULL); assert(ptr != NULL);
if (*ptr == '\0') { if (*ptr == '\0') {
@ -335,6 +340,8 @@ void parse_syntax(char *ptr)
endsyntax->linter = NULL; endsyntax->linter = NULL;
endsyntax->formatter = NULL; endsyntax->formatter = NULL;
opensyntax = TRUE;
#ifdef DEBUG #ifdef DEBUG
fprintf(stderr, "Starting a new syntax type: \"%s\"\n", nameptr); fprintf(stderr, "Starting a new syntax type: \"%s\"\n", nameptr);
#endif #endif
@ -691,7 +698,7 @@ void parse_colors(char *ptr, bool icase)
assert(ptr != NULL); assert(ptr != NULL);
if (syntaxes == NULL) { if (!opensyntax) {
rcfile_error( rcfile_error(
N_("Cannot add a color command without a syntax command")); N_("Cannot add a color command without a syntax command"));
return; return;
@ -862,7 +869,7 @@ void grab_and_store(char *ptr, const char *kind, regexlisttype **storage)
{ {
regexlisttype *lastthing; regexlisttype *lastthing;
if (syntaxes == NULL) { if (!opensyntax) {
rcfile_error( rcfile_error(
N_("A '%s' command requires a preceding 'syntax' command"), kind); N_("A '%s' command requires a preceding 'syntax' command"), kind);
return; return;
@ -933,7 +940,7 @@ void parse_linter(char *ptr)
{ {
assert(ptr != NULL); assert(ptr != NULL);
if (syntaxes == NULL) { if (!opensyntax) {
rcfile_error( rcfile_error(
N_("Cannot add a linter without a syntax command")); N_("Cannot add a linter without a syntax command"));
return; return;
@ -959,7 +966,7 @@ void parse_formatter(char *ptr)
{ {
assert(ptr != NULL); assert(ptr != NULL);
if (syntaxes == NULL) { if (!opensyntax) {
rcfile_error( rcfile_error(
N_("Cannot add formatter without a syntax command")); N_("Cannot add formatter without a syntax command"));
return; return;
@ -1062,6 +1069,7 @@ void parse_rcfile(FILE *rcstream
rcfile_error(N_("Could not find syntax \"%s\" to extend"), syntaxname); rcfile_error(N_("Could not find syntax \"%s\" to extend"), syntaxname);
continue; continue;
} else { } else {
opensyntax = TRUE;
end_syn_save = endsyntax; end_syn_save = endsyntax;
endsyntax = ts; endsyntax = ts;
keyword = ptr; keyword = ptr;
@ -1313,6 +1321,8 @@ void parse_rcfile(FILE *rcstream
endsyntax->desc); endsyntax->desc);
#endif #endif
opensyntax = FALSE;
free(buf); free(buf);
fclose(rcstream); fclose(rcstream);
lineno = 0; lineno = 0;