Check if the for variable is invalid before trying to set it

This commit is contained in:
Fabian Homborg 2021-10-26 16:58:30 +02:00
parent e84dad5432
commit d9f094db1a

View file

@ -438,6 +438,11 @@ end_execution_reason_t parse_execution_context_t::run_for_statement(
FAILED_EXPANSION_VARIABLE_NAME_ERR_MSG, for_var_name.c_str());
}
if (!valid_var_name(for_var_name)) {
return report_error(STATUS_INVALID_ARGS, header.var_name, BUILTIN_ERR_VARNAME, L"for",
for_var_name.c_str());
}
// Get the contents to iterate over.
wcstring_list_t arguments;
ast_args_list_t arg_nodes = get_argument_nodes(header.args);
@ -460,11 +465,6 @@ end_execution_reason_t parse_execution_context_t::run_for_statement(
}
assert(retval == ENV_OK);
if (!valid_var_name(for_var_name)) {
return report_error(STATUS_INVALID_ARGS, header.var_name, BUILTIN_ERR_VARNAME, L"for",
for_var_name.c_str());
}
trace_if_enabled(*parser, L"for", arguments);
block_t *fb = parser->push_block(block_t::for_block());