mirror of
https://git.savannah.gnu.org/git/bison.git
synced 2026-03-09 20:33:03 +00:00
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:
@@ -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 ? "?\""
|
||||
: "?\")");
|
||||
}
|
||||
}
|
||||
|
||||
/*--------------------------------------------.
|
||||
|
||||
@@ -1395,11 +1395,6 @@ AT_CLEANUP
|
||||
AT_SETUP([Torturing the Scanner])
|
||||
|
||||
AT_BISON_OPTION_PUSHDEFS
|
||||
AT_DATA([input.y], [])
|
||||
AT_BISON_CHECK([input.y], [1], [],
|
||||
[[input.y:1.1: error: unexpected end of file
|
||||
]])
|
||||
|
||||
|
||||
AT_DATA([input.y],
|
||||
[{}
|
||||
@@ -2506,6 +2501,99 @@ input.y:5.19: error: invalid character after \-escape: \001
|
||||
AT_CLEANUP
|
||||
|
||||
|
||||
## ------------------------ ##
|
||||
## Unexpected end of file. ##
|
||||
## ------------------------ ##
|
||||
|
||||
AT_SETUP([[Unexpected end of file]])
|
||||
|
||||
|
||||
AT_DATA([input.y], [])
|
||||
AT_BISON_CHECK([-fcaret input.y], [1], [],
|
||||
[[input.y:1.1: error: unexpected end of file
|
||||
]])
|
||||
|
||||
|
||||
AT_DATA_NO_FINAL_EOL([char.y],
|
||||
[[%token FOO ']])
|
||||
|
||||
AT_BISON_CHECK([-fcaret char.y], [1], [],
|
||||
[[char.y:1.12: error: missing "'" at end of file
|
||||
1 | %token FOO '
|
||||
| ^
|
||||
char.y:1.12: error: empty character literal
|
||||
1 | %token FOO '
|
||||
| ^
|
||||
]])
|
||||
|
||||
|
||||
AT_DATA_NO_FINAL_EOL([escape-in-char.y],
|
||||
[[%token FOO '\]])
|
||||
|
||||
AT_BISON_CHECK([-fcaret escape-in-char.y], [1], [],
|
||||
[[escape-in-char.y:1.12-13: error: missing '?\'' at end of file
|
||||
1 | %token FOO '\
|
||||
| ^~
|
||||
escape-in-char.y:1.14: error: unexpected end of file
|
||||
1 | %token FOO '\
|
||||
| ^
|
||||
]])
|
||||
|
||||
|
||||
AT_DATA_NO_FINAL_EOL([string.y],
|
||||
[[%token FOO "]])
|
||||
|
||||
AT_BISON_CHECK([-fcaret string.y], [1], [],
|
||||
[[string.y:1.12: error: missing '"' at end of file
|
||||
1 | %token FOO "
|
||||
| ^
|
||||
string.y:1.13: error: unexpected end of file
|
||||
1 | %token FOO "
|
||||
| ^
|
||||
]])
|
||||
|
||||
|
||||
AT_DATA_NO_FINAL_EOL([escape-in-string.y],
|
||||
[[%token FOO "\]])
|
||||
|
||||
AT_BISON_CHECK([-fcaret escape-in-string.y], [1], [],
|
||||
[[escape-in-string.y:1.12-13: error: missing '?"' at end of file
|
||||
1 | %token FOO "\
|
||||
| ^~
|
||||
escape-in-string.y:1.14: error: unexpected end of file
|
||||
1 | %token FOO "\
|
||||
| ^
|
||||
]])
|
||||
|
||||
|
||||
AT_DATA_NO_FINAL_EOL([tstring.y],
|
||||
[[%token FOO _("]])
|
||||
|
||||
AT_BISON_CHECK([-fcaret tstring.y], [1], [],
|
||||
[[tstring.y:1.12-14: error: missing '")' at end of file
|
||||
1 | %token FOO _("
|
||||
| ^~~
|
||||
tstring.y:1.15: error: unexpected end of file
|
||||
1 | %token FOO _("
|
||||
| ^
|
||||
]])
|
||||
|
||||
|
||||
AT_DATA_NO_FINAL_EOL([escape-in-tstring.y],
|
||||
[[%token FOO _("\]])
|
||||
|
||||
AT_BISON_CHECK([-fcaret escape-in-tstring.y], [1], [],
|
||||
[[escape-in-tstring.y:1.12-15: error: missing '?")' at end of file
|
||||
1 | %token FOO _("\
|
||||
| ^~~~
|
||||
escape-in-tstring.y:1.16: error: unexpected end of file
|
||||
1 | %token FOO _("\
|
||||
| ^
|
||||
]])
|
||||
|
||||
AT_CLEANUP
|
||||
|
||||
|
||||
## ------------------------- ##
|
||||
## LAC: Errors for %define. ##
|
||||
## ------------------------- ##
|
||||
|
||||
Reference in New Issue
Block a user