From 6e24b26e2c9b6b2f1f886eb4d98470fc6c6319b8 Mon Sep 17 00:00:00 2001 From: axel Date: Thu, 2 Nov 2006 23:45:37 +1000 Subject: [PATCH] Fix the code for ignoring infinite recursion darcs-hash:20061102134537-ac50b-2dddd06dd77c362caf44c9160acc29b76278b230.gz --- parser.c | 36 ++++++++++++++++++++++++++++++------ parser.h | 5 +++-- 2 files changed, 33 insertions(+), 8 deletions(-) diff --git a/parser.c b/parser.c index c92367541..689d8ad41 100644 --- a/parser.c +++ b/parser.c @@ -1669,6 +1669,7 @@ static void parse_job_argument_list( process_t *p, return; } + /* static void print_block_stack( block_t *b ) { @@ -1931,16 +1932,31 @@ static int parse_job( process_t *p, int nxt_forbidden=0; wchar_t *forbid; - if( current_block->type == FUNCTION_CALL ) + int is_function_call=0; + + /* + This is a bit fragile. It is a test to see if we are + inside of function call, but not inside a block in that + function call. If, in the future, the rules for what + block scopes are pushed on function invocation changes, + then this check will break. + */ + if( ( current_block->type == TOP ) && + ( current_block->outer ) && + ( current_block->outer->type == FUNCTION_CALL ) ) + is_function_call = 1; + + /* + If we are directly in a function, and this is the first + command of the block, then the function we are executing + may not be called, since that would mean an infinite + recursion. + */ + if( is_function_call && !current_block->had_command ) { forbid = (wchar_t *)(al_get_count( forbidden_function)?al_peek( forbidden_function ):0); nxt_forbidden = forbid && (wcscmp( forbid, nxt) == 0 ); } - - /* - Make feeble attempt to avoid infinite recursion. Will at - least catch some accidental infinite recursion calls. - */ if( !nxt_forbidden && function_exists( nxt ) ) { @@ -2198,6 +2214,14 @@ static int parse_job( process_t *p, } } + if( !error_code ) + { + if( !is_new_block ) + { + current_block->had_command = 1; + } + } + if( error_code ) { /* diff --git a/parser.h b/parser.h index d873a1fbd..7bf6b8866 100644 --- a/parser.h +++ b/parser.h @@ -47,7 +47,8 @@ typedef struct block int type; /**< Type of block. Can be one of WHILE, FOR, IF and FUNCTION */ int skip; /**< Whether execution of the commands in this block should be skipped */ int tok_pos; /**< The start index of the block */ - + int had_command; /**< Set to non-zero once a command has been executed in this block */ + /** Status for the current loop block. Can be any of the values from the loop_status enum. */ @@ -210,7 +211,7 @@ int eval_args( const wchar_t *line, array_list_t *output ); /** - Sets the current error + Sets the current evaluation error. This function should only be used by libraries that are called by \param ec The new error code \param p The character offset at which the error occured