mirror of
https://github.com/fish-shell/fish-shell
synced 2025-01-13 13:39:02 +00:00
Remove undefined behavior from parse_error().
Having function that takes arbitrary number of arguments without actually reading them is undefined behavior, as it could cause stack to be in the corrupted state. Now arguments after token are parsed, even if they aren't needed. See also: http://asciinema.org/a/5904
This commit is contained in:
parent
e8ba3c2f4d
commit
22d22f6aa8
1 changed files with 17 additions and 10 deletions
|
@ -341,6 +341,7 @@ class parse_ll_t
|
|||
bool top_node_handle_terminal_types(parse_token_t token);
|
||||
|
||||
void parse_error(const wchar_t *expected, parse_token_t token);
|
||||
void parse_error(parse_token_t token);
|
||||
void parse_error(parse_token_t token, const wchar_t *format, ...);
|
||||
void append_error_callout(wcstring &error_message, parse_token_t token);
|
||||
|
||||
|
@ -551,11 +552,15 @@ void parse_ll_t::acquire_output(parse_node_tree_t *output, parse_error_list_t *e
|
|||
this->symbol_stack.clear();
|
||||
}
|
||||
|
||||
void parse_ll_t::parse_error(parse_token_t token, const wchar_t *fmt, ...)
|
||||
void parse_ll_t::parse_error(parse_token_t token)
|
||||
{
|
||||
this->fatal_errored = true;
|
||||
if (this->should_generate_error_messages)
|
||||
}
|
||||
|
||||
void parse_ll_t::parse_error(parse_token_t token, const wchar_t *fmt, ...)
|
||||
{
|
||||
parse_error(token);
|
||||
|
||||
//this->dump_stack();
|
||||
parse_error_t err;
|
||||
|
||||
|
@ -564,6 +569,8 @@ void parse_ll_t::parse_error(parse_token_t token, const wchar_t *fmt, ...)
|
|||
err.text = vformat_string(fmt, va);
|
||||
va_end(va);
|
||||
|
||||
if (this->should_generate_error_messages)
|
||||
{
|
||||
err.source_start = token.source_start;
|
||||
err.source_length = token.source_length;
|
||||
this->errors.push_back(err);
|
||||
|
@ -730,7 +737,7 @@ void parse_ll_t::accept_tokens(parse_token_t token1, parse_token_t token2)
|
|||
}
|
||||
else
|
||||
{
|
||||
this->parse_error(token1, NULL);
|
||||
this->parse_error(token1);
|
||||
}
|
||||
// parse_error sets fatal_errored, which ends the loop
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue