fix: unterminated \-escape

An assertion failed when the last character is a '\' and we're in a
character or a string.
Reported by Agency for Defense Development.
https://lists.gnu.org/r/bug-bison/2020-08/msg00009.html

* src/scan-gram.l: Catch unterminated escapes.
* tests/input.at (Unexpected end of file): New.
This commit is contained in:
Akim Demaille
2020-08-08 07:36:34 +02:00
parent b7aab2dbad
commit b801b7b670
2 changed files with 106 additions and 10 deletions

View File

@@ -567,6 +567,8 @@ eqopt ({sp}=)?
_("POSIX Yacc does not support string literals"));
RETURN_VALUE (STRING, last_string);
}
<<EOF>> unexpected_eof (token_start, "\"");
"\n" unexpected_newline (token_start, "\"");
}
<SC_ESCAPED_TSTRING>
@@ -580,13 +582,10 @@ eqopt ({sp}=)?
_("POSIX Yacc does not support string literals"));
RETURN_VALUE (TSTRING, last_string);
}
<<EOF>> unexpected_eof (token_start, "\")");
"\n" unexpected_newline (token_start, "\")");
}
<SC_ESCAPED_STRING,SC_ESCAPED_TSTRING>
{
<<EOF>> unexpected_eof (token_start, "\"");
"\n" unexpected_newline (token_start, "\"");
}
/*----------------------------------------------------------.
@@ -692,6 +691,15 @@ eqopt ({sp}=)?
p);
STRING_1GROW ('?');
}
"\\" {
// None of the other rules matched: the last character of this
// file is "\". But Flex does not support "\\<<EOF>>".
unexpected_eof (token_start,
YY_START == SC_ESCAPED_CHARACTER ? "?'"
: YY_START == SC_ESCAPED_STRING ? "?\""
: "?\")");
}
}
/*--------------------------------------------.