* src/rcfile.c (grab_and_store): Do not drop regexes that were
gathered earlier. This fixes Savannah bug #47285.
* 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>
* doc/man/nanorc.5, doc/texinfo/nano.texi, doc/syntax/nanorc.nanorc,
static char *nanorc = NULL;
/* The path to the rcfile we're parsing. */
#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;
/* The end of the list of syntaxes. */
static colortype *endcolor = NULL;
regexlisttype *endext = NULL;
/* The end of the extensions list for this syntax. */
+ opensyntax = FALSE;
+
assert(ptr != NULL);
if (*ptr == '\0') {
endsyntax->linter = NULL;
endsyntax->formatter = NULL;
+ opensyntax = TRUE;
+
#ifdef DEBUG
fprintf(stderr, "Starting a new syntax type: \"%s\"\n", nameptr);
#endif
assert(ptr != NULL);
- if (syntaxes == NULL) {
+ if (!opensyntax) {
rcfile_error(
N_("Cannot add a color command without a syntax command"));
return;
{
regexlisttype *lastthing;
- if (syntaxes == NULL) {
+ if (!opensyntax) {
rcfile_error(
N_("A '%s' command requires a preceding 'syntax' command"), kind);
return;
{
assert(ptr != NULL);
- if (syntaxes == NULL) {
+ if (!opensyntax) {
rcfile_error(
N_("Cannot add a linter without a syntax command"));
return;
{
assert(ptr != NULL);
- if (syntaxes == NULL) {
+ if (!opensyntax) {
rcfile_error(
N_("Cannot add formatter without a syntax command"));
return;
rcfile_error(N_("Could not find syntax \"%s\" to extend"), syntaxname);
continue;
} else {
+ opensyntax = TRUE;
end_syn_save = endsyntax;
endsyntax = ts;
keyword = ptr;
endsyntax->desc);
#endif
+ opensyntax = FALSE;
+
free(buf);
fclose(rcstream);
lineno = 0;