From d9f094db1a7243b379e074509acdbc847378fb93 Mon Sep 17 00:00:00 2001 From: Fabian Homborg Date: Tue, 26 Oct 2021 16:58:30 +0200 Subject: [PATCH] Check if the for variable is invalid before trying to set it --- src/parse_execution.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/parse_execution.cpp b/src/parse_execution.cpp index f8d072448..5c9b87dd7 100644 --- a/src/parse_execution.cpp +++ b/src/parse_execution.cpp @@ -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());