From a27e6ec35ac8e7960323f999aed1860e1cbd2d24 Mon Sep 17 00:00:00 2001 From: Chet Ramey Date: Mon, 11 Sep 2017 09:24:36 -0400 Subject: [PATCH] commit bash-20170901 snapshot --- CWRU/CWRU.chlog | 10 ++++++++++ execute_cmd.c | 26 +++++++++++++++++++++++--- shell.c | 2 +- 3 files changed, 34 insertions(+), 4 deletions(-) diff --git a/CWRU/CWRU.chlog b/CWRU/CWRU.chlog index 08b11eee..6a2491db 100644 --- a/CWRU/CWRU.chlog +++ b/CWRU/CWRU.chlog @@ -14291,3 +14291,13 @@ builtins/read.def - struct ttsave: make the attrs member a struct, not a pointer, to force a structure copy that will survive a longjmp to another context. Leaving it as a pointer to a local struct is not portable + + 9/10 + ---- +execute_cmd.c + - execute_builtin: make sure that we set up the unwind-protect for + pop_scope (temporary_env is non-zero) so that the temporary env + is propagated to the current environment only for special builtins + (source/eval/unset) not run by the command builtin + (flags & CMD_COMMAND_BUILTIN == 0). Fixes bug reported by + Martijn Dekker diff --git a/execute_cmd.c b/execute_cmd.c index 4d71932b..8d38378e 100644 --- a/execute_cmd.c +++ b/execute_cmd.c @@ -603,6 +603,16 @@ execute_command_internal (command, asynchronous, pipe_in, pipe_out, user_subshell = command->type == cm_subshell || ((command->flags & CMD_WANT_SUBSHELL) != 0); +#if defined (TIME_BEFORE_SUBSHELL) + if ((command->flags & CMD_TIME_PIPELINE) && user_subshell && asynchronous == 0) + { + command->flags |= CMD_FORCE_SUBSHELL; + exec_result = time_command (command, asynchronous, pipe_in, pipe_out, fds_to_close); + currently_executing_command = (COMMAND *)NULL; + return (exec_result); + } +#endif + if (command->type == cm_subshell || (command->flags & (CMD_WANT_SUBSHELL|CMD_FORCE_SUBSHELL)) || (shell_control_structure (command->type) && @@ -4510,10 +4520,11 @@ execute_builtin (builtin, words, flags, subshell) int flags, subshell; { int result, eval_unwind, ignexit_flag, old_e_flag; - int isbltinenv; + int isbltinenv, should_keep; char *error_trap; error_trap = 0; + should_keep = 0; /* The eval builtin calls parse_and_execute, which does not know about the setting of flags, and always calls the execution functions with @@ -4549,10 +4560,17 @@ execute_builtin (builtin, words, flags, subshell) problem only with the `unset', `source' and `eval' builtins. `mapfile' is a special case because it uses evalstring (same as eval or source) to run its callbacks. */ + /* SHOULD_KEEP is for the pop_scope call below; it only matters when + posixly_correct is set, but we should propagate the temporary environment + to the enclosing environment only for special builtins. */ isbltinenv = (builtin == source_builtin || builtin == eval_builtin || builtin == unset_builtin || builtin == mapfile_builtin); + should_keep = isbltinenv && builtin != mapfile_builtin; #if defined (HISTORY) && defined (READLINE) if (builtin == fc_builtin || builtin == read_builtin) - isbltinenv = 1; + { + isbltinenv = 1; + should_keep = 0; + } #endif if (isbltinenv) @@ -4563,8 +4581,10 @@ execute_builtin (builtin, words, flags, subshell) if (temporary_env) { push_scope (VC_BLTNENV, temporary_env); + if (flags & CMD_COMMAND_BUILTIN) + should_keep = 0; if (subshell == 0) - add_unwind_protect (pop_scope, (flags & CMD_COMMAND_BUILTIN) ? 0 : "1"); + add_unwind_protect (pop_scope, should_keep ? "1" : 0); temporary_env = (HASH_TABLE *)NULL; } } diff --git a/shell.c b/shell.c index 013fece3..d395c8db 100644 --- a/shell.c +++ b/shell.c @@ -1,6 +1,6 @@ /* shell.c -- GNU's idea of the POSIX shell specification. */ -/* Copyright (C) 1987-2015 Free Software Foundation, Inc. +/* Copyright (C) 1987-2017 Free Software Foundation, Inc. This file is part of GNU Bash, the Bourne Again SHell.