From c21b3727a7457c1bcc7037f58699d948ae385ad4 Mon Sep 17 00:00:00 2001 From: Chet Ramey Date: Mon, 21 May 2018 10:28:44 -0400 Subject: [PATCH] commit bash-20180511 snapshot --- CHANGES | 89 ++++++++++++++++++++++++- COMPAT | 11 +++- CWRU/CWRU.chlog | 38 +++++++++++ MANIFEST | 1 + NEWS | 115 +++++++++++++++++++++++++++++++++ NEWS-5.0 | 113 ++++++++++++++++++++++++++++++++ README | 6 +- bashhist.c | 9 ++- builtins/evalstring.c | 1 + builtins/shopt.def | 15 +++++ config-top.h | 7 ++ doc/bashref.texi | 2 +- examples/loadables/Makefile.in | 2 +- execute_cmd.c | 12 ++++ lib/readline/readline.h | 4 +- po/Makefile.in.in | 2 +- support/Makefile.in | 7 +- tests/posixexp5.sub | 2 +- tests/redir.right | 2 +- tests/redir.tests | 3 + tests/test-glue-functions | 2 +- tests/trap.right | 4 ++ tests/trap.tests | 3 + tests/trap6.sub | 15 +++++ tests/varenv.right | 11 ++++ tests/varenv.sh | 2 +- tests/varenv12.sub | 58 +++++++++++++++++ variables.c | 15 ++++- version.c | 4 +- version2.c | 4 +- 30 files changed, 533 insertions(+), 26 deletions(-) create mode 100644 NEWS-5.0 create mode 100644 tests/trap6.sub diff --git a/CHANGES b/CHANGES index 98947eb13..341b91cab 100644 --- a/CHANGES +++ b/CHANGES @@ -267,6 +267,82 @@ iiii. Fixed a problem with splitting double-quoted words for programmable completion when the double quote immediately follows another word delimiter. +jjjj. Fixed a bug resulting in a use-after-free if two file descriptors share + the same input buffer. + +kkkk. The error message resulting from ${x:?} and ${x?} now differs depending + on whether the variable is null or unset. + +llll. In Posix mode, the shell exits if a variable assignment fails and precedes + an empty simple command (after expansion). + +mmmm. Fixed a timing problem with SIGALRM that could cause the read builtin to + drop characters. + +nnnn. Added code to deal with kill(2) failing to send the shell a fatal signal + due to Linux pid namespace peculiarities. + +oooo. Fixed a bug that made \C-@ (NUL) unusable in key sequences used for + `bind -x' commands. + +pppp. Fixed a bug that could cause SIGINT recursion when running an external + command in a trap the shell takes after a command exits due to SIGINT. + +qqqq. Make sure the shell turns off job control before running the command- + not-found handle, so the command doesn't try to manipulate process + groups. + +rrrr. Fixed a problem with timing process substitutions that caused the shell + to print timing information for the calling command. + +ssss. Fixed a bug that caused backquotes in a here-document delimiter to mark + the delimiter as quoted (inhibiting expansion of the here-document + contents). + +tttt. Fixed several problems with 0x01 and 0x177 in case pattern lists and + conditional command pattern matches. + +uuuu. Fixed a bug that could cause the pattern matching engine to not recognize + locale-specific character classes. + +vvvv. The auto-configuration now tests for /dev/stdin and /dev/fd independently. + +wwww. The `globstar' code now skips over symbolic links to directories, + preventing them from being scanned twice. + +xxxx. When running `bind -x' commands, bash now sets READLINE_POINT based on + the number of characters in the readline line buffer, not the number of + bytes. + +yyyy. Fixed a problem that could cause recursive trap evaluation of the RETURN + trap when using `eval return'. + +zzzz. Fixed a bug with expanding 0x01 in an unquoted here-document. + +aaaaa. The process substitution code now closes and unlinks FIFOs when the + process on the other side exits, in order to prevent SIGPIPE or + waiting until a FIFO opened for read has a writer. + +bbbbb. Fixed a bug with recursive calls to the parser overwriting the token in + an {id}>foo construct. + +ccccc. After a Posix discussion, the pattern matching engine just skips over + invalid character classes in bracket expressions, instead of matching + them like individual characters in the expression. + +ddddd. Fixed a posix-mode problem with variable scoping when creating variables + from assignment statements preceding special builtins. + +eeeee. Fixed a bug that could cause patterns containing backslashes to not be + run through the pattern matching engine. + +fffff. Fixed a bug that could cause redirections to compound commands to not + be `undone' if the file descriptor in the redirection was closed when + the redirection was initially processed. + +ggggg. Fixed a bug that could cause buffer corruption when using `bind -x' in + a command execute as a result of a key binding installed by `bind -x'. + 2. Changes to Readline a. Added a guard to prevent nested macros from causing an infinite expansion @@ -283,7 +359,7 @@ d. Added support for keyboard timeouts when an ESC character is the last e. There are several performance improvements when in a UTF-8 locale. -f. Readline does a better job of preserving the original set of blocked = +f. Readline does a better job of preserving the original set of blocked signals when using pselect() to wait for input. g. Fixed a bug that caused multibyte characters in macros to be mishandled. @@ -331,6 +407,9 @@ u. If there is a key bound to the tty's VDISCARD special character, readline v. Fixed a problem with exiting bracketed paste mode on terminals that assume the bracketed paste mode character sequence contains visible characters. +w. Fixed a bug that could cause a key binding command to refer to an + uninitialized variable. + 3. New Features in Bash a. The `wait' builtin can now wait for the last process substitution created. @@ -406,6 +485,14 @@ x. The shell only sets up BASH_ARGV and BASH_ARGC at startup if extended debugging mode is active. The old behavior of unconditionally setting them is available as part of the shell compatibility options. +y. The `umask' builtin now allows modes and masks greater than octal 777. + +z. The `times' builtin now honors the current locale when printing a decimal + point. + +aa. There is a new (disabled by default, undocumented) shell option to enable + and disable sending history to syslog at runtime. + 4. New Features in Readline a. Non-incremental vi-mode search (`N', `n') can search for a shell pattern, as diff --git a/COMPAT b/COMPAT index 3ed6762e5..aa0019fa7 100644 --- a/COMPAT +++ b/COMPAT @@ -2,9 +2,9 @@ Compatibility with previous versions ==================================== This document details the incompatibilities between this version of bash, -bash-4.4, and the previous widely-available versions, bash-3.x (which is -still the `standard' version for Mac OS X), 4.1/4.2 (which are still -standard on a few Linux distributions), and bash-4.3, the current +bash-5.0, and the previous widely-available versions, bash-3.x (which is +still the `standard' version for Mac OS X), 4.2/4.3 (which are still +standard on a few Linux distributions), and bash-4.4, the current widely-available version. These were discovered by users of bash-2.x through 4.x, so this list is not comprehensive. Some of these incompatibilities occur between the current version and versions 2.0 and @@ -391,6 +391,11 @@ above. argument to `declare' or a similar builtin expands to a word that looks like a compound array assignment (e.g. declare w=$x where x='(foo)'). +60. Bash-5.0 only sets up BASH_ARGV and BASH_ARGC at startup if extended + debugging mode is active. The old behavior of unconditionally setting + BASH_ARGC and BASH_ARGV is available at compatibility levels less than + or equal to 44. + Shell Compatibility Level ========================= diff --git a/CWRU/CWRU.chlog b/CWRU/CWRU.chlog index 1cacea208..4631ac550 100644 --- a/CWRU/CWRU.chlog +++ b/CWRU/CWRU.chlog @@ -15358,3 +15358,41 @@ bashline.c - bash_execute_unix_command: make sure that parse_and_execute is called with newly-allocated memory to avoid prematurely freeing the command. Report and fix from Koichi Murase + + 5/7 + --- +builtins/shopt.def + - syslog_history: a shell option to control whether history is logged + to syslog; can be modified at runtime. Original patch from + Siteshwar Vashisht + +config-top.h + - SYSLOG_SHOPT: new configurable option, determines whether there is a + shell option to control syslogging history lines at runtime and sets + the default value of the option + +bashline.c + - syslog_history: new variable to control whether history lines are + sent to syslog; default value is the value of SYSLOG_SHOPT (or 1 + if that's not defined) + - bash_add_history: send history lines to syslog if syslog_history is + non-zero + + 5/10 + ---- + +variables.c + - push_var_context: if we are in Posix mode and manipulating the + temporary environment (temporary_env), implement behavior specified + in Posix interp 1009 and make sure that temporary assignments + preceding function calls modify the current environment *before* + the function is executed. + +[bash-5.0-alpha frozen] + + 5/12 + ---- +execute_cmd.c + - execute_in_subshell: subshells should set loop_level == 0, since + they are no longer "enclosed" by the loop, according to posix. + Report from Aeron.E. Wang diff --git a/MANIFEST b/MANIFEST index 4f242c82d..56528b5bf 100644 --- a/MANIFEST +++ b/MANIFEST @@ -1341,6 +1341,7 @@ tests/trap2a.sub f 755 tests/trap3.sub f tests/trap4.sub f tests/trap5.sub f +tests/trap6.sub f tests/type.tests f tests/type.right f tests/type1.sub f diff --git a/NEWS b/NEWS index 931dc846b..66cbf97dc 100644 --- a/NEWS +++ b/NEWS @@ -1,3 +1,118 @@ +This is a terse description of the new features added to bash-5.0 since +the release of bash-4.4. As always, the manual page (doc/bash.1) is +the place to look for complete descriptions. + +1. New Features in Bash + +a. The `wait' builtin can now wait for the last process substitution created. + +b. There is an EPOCHSECONDS variable, which expands to the time in seconds + since the Unix epoch. + +c. There is an EPOCHREALTIME variable, which expands to the time in seconds + since the Unix epoch with microsecond granularity. + +d. New loadable builtins: rm, stat, fdflags. + +e. BASH_ARGV0: a new variable that expands to $0 and sets $0 on assignment. + +f. When supplied a numeric argument, the shell-expand-line bindable readline + command does not perform quote removal and suppresses command and process + substitution. + +g. `history -d' understands negative arguments: negative arguments offset from + the end of the history list. + +h. The `name' argument to the `coproc' reserved word now undergoes word + expansion, so unique coprocs can be created in loops. + +i. A nameref name resolution loop in a function now resolves to a variable by + that name in the global scope. + +j. The `wait' builtin now has a `-f' option, which signfies to wait until the + specified job or process terminates, instead of waiting until it changes + state. + +k. There is a define in config-top.h that allows the shell to use a static + value for $PATH, overriding whatever is in the environment at startup, for + use by the restricted shell. + +l. Process substitution does not inherit the `v' option, like command + substitution. + +m. If a non-interactive shell with job control enabled detects that a foreground + job died due to SIGINT, it acts as if it received the SIGINT. + +n. The SIGCHLD trap is run once for each exiting child process even if job + control is not enabled when the shell is in Posix mode. + +o. A new shopt option: localvar_inherit; if set, a local variable inherits the + value of a variable with the same name at the nearest preceding scope. + +p. `bind -r' now checks whether a key sequence is bound before binding it to + NULL, to avoid creating keymaps for a multi-key sequence. + +q. A numeric argument to the line editing `operate-and-get-next' command + specifies which history entry to use. + +r. The positional parameters are now assigned before running the shell startup + files, so startup files can use $@. + +s. There is a compile-time option that forces the shell to disable the check + for an inherited OLDPWD being a directory. + +t. The `history' builtin can now delete ranges of history entries using + `-d start-end'. + +u. The `vi-edit-and-execute-command' bindable readline command now puts readline + back in vi insertion mode after executing commands from the edited file. + +v. The command completion code now matches aliases and shell function names + case-insensitively if the readline completion-ignore-case variable is set. + +w. There is a new `assoc_expand_once' shell option that attempts to expand + associative array subscripts only once. + +x. The shell only sets up BASH_ARGV and BASH_ARGC at startup if extended + debugging mode is active. The old behavior of unconditionally setting them + is available as part of the shell compatibility options. + +y. The `umask' builtin now allows modes and masks greater than octal 777. + +z. The `times' builtin now honors the current locale when printing a decimal + point. + +aa. There is a new (disabled by default, undocumented) shell option to enable + and disable sending history to syslog at runtime. + +2. New Features in Readline + +a. Non-incremental vi-mode search (`N', `n') can search for a shell pattern, as + Posix specifies (uses fnmatch(3) if available). + +b. There are new `next-screen-line' and `previous-screen-line' bindable + commands, which move the cursor to the same column in the next, or previous, + physical line, respectively. + +c. There are default key bindings for control-arrow-key key combinations. + +d. A negative argument (-N) to `quoted-insert' means to insert the next N + characters using quoted-insert. + +e. New public function: rl_check_signals(), which allows applications to + respond to signals that readline catches while waiting for input using + a custom read function. + +f. There is new support for conditionally testing the readline version in an + inputrc file, with a full set of arithmetic comparison operators available. + +g. There is a simple variable comparison facility available for use within an + inputrc file. Allowable operators are equality and inequality; string + variables may be compared to a value; boolean variables must be compared to + either `on' or `off'; variable names are separated from the operator by + whitespace. + +------------------------------------------------------------------------------- This is a terse description of the new features added to bash-4.4 since the release of bash-4.3. As always, the manual page (doc/bash.1) is the place to look for complete descriptions. diff --git a/NEWS-5.0 b/NEWS-5.0 new file mode 100644 index 000000000..e8ca40aac --- /dev/null +++ b/NEWS-5.0 @@ -0,0 +1,113 @@ +This is a terse description of the new features added to bash-5.0 since +the release of bash-4.4. As always, the manual page (doc/bash.1) is +the place to look for complete descriptions. + +1. New Features in Bash + +a. The `wait' builtin can now wait for the last process substitution created. + +b. There is an EPOCHSECONDS variable, which expands to the time in seconds + since the Unix epoch. + +c. There is an EPOCHREALTIME variable, which expands to the time in seconds + since the Unix epoch with microsecond granularity. + +d. New loadable builtins: rm, stat, fdflags. + +e. BASH_ARGV0: a new variable that expands to $0 and sets $0 on assignment. + +f. When supplied a numeric argument, the shell-expand-line bindable readline + command does not perform quote removal and suppresses command and process + substitution. + +g. `history -d' understands negative arguments: negative arguments offset from + the end of the history list. + +h. The `name' argument to the `coproc' reserved word now undergoes word + expansion, so unique coprocs can be created in loops. + +i. A nameref name resolution loop in a function now resolves to a variable by + that name in the global scope. + +j. The `wait' builtin now has a `-f' option, which signfies to wait until the + specified job or process terminates, instead of waiting until it changes + state. + +k. There is a define in config-top.h that allows the shell to use a static + value for $PATH, overriding whatever is in the environment at startup, for + use by the restricted shell. + +l. Process substitution does not inherit the `v' option, like command + substitution. + +m. If a non-interactive shell with job control enabled detects that a foreground + job died due to SIGINT, it acts as if it received the SIGINT. + +n. The SIGCHLD trap is run once for each exiting child process even if job + control is not enabled when the shell is in Posix mode. + +o. A new shopt option: localvar_inherit; if set, a local variable inherits the + value of a variable with the same name at the nearest preceding scope. + +p. `bind -r' now checks whether a key sequence is bound before binding it to + NULL, to avoid creating keymaps for a multi-key sequence. + +q. A numeric argument to the line editing `operate-and-get-next' command + specifies which history entry to use. + +r. The positional parameters are now assigned before running the shell startup + files, so startup files can use $@. + +s. There is a compile-time option that forces the shell to disable the check + for an inherited OLDPWD being a directory. + +t. The `history' builtin can now delete ranges of history entries using + `-d start-end'. + +u. The `vi-edit-and-execute-command' bindable readline command now puts readline + back in vi insertion mode after executing commands from the edited file. + +v. The command completion code now matches aliases and shell function names + case-insensitively if the readline completion-ignore-case variable is set. + +w. There is a new `assoc_expand_once' shell option that attempts to expand + associative array subscripts only once. + +x. The shell only sets up BASH_ARGV and BASH_ARGC at startup if extended + debugging mode is active. The old behavior of unconditionally setting them + is available as part of the shell compatibility options. + +y. The `umask' builtin now allows modes and masks greater than octal 777. + +z. The `times' builtin now honors the current locale when printing a decimal + point. + +aa. There is a new (disabled by default, undocumented) shell option to enable + and disable sending history to syslog at runtime. + +2. New Features in Readline + +a. Non-incremental vi-mode search (`N', `n') can search for a shell pattern, as + Posix specifies (uses fnmatch(3) if available). + +b. There are new `next-screen-line' and `previous-screen-line' bindable + commands, which move the cursor to the same column in the next, or previous, + physical line, respectively. + +c. There are default key bindings for control-arrow-key key combinations. + +d. A negative argument (-N) to `quoted-insert' means to insert the next N + characters using quoted-insert. + +e. New public function: rl_check_signals(), which allows applications to + respond to signals that readline catches while waiting for input using + a custom read function. + +f. There is new support for conditionally testing the readline version in an + inputrc file, with a full set of arithmetic comparison operators available. + +g. There is a simple variable comparison facility available for use within an + inputrc file. Allowable operators are equality and inequality; string + variables may be compared to a value; boolean variables must be compared to + either `on' or `off'; variable names are separated from the operator by + whitespace. diff --git a/README b/README index 66a6cb470..c28d63df8 100644 --- a/README +++ b/README @@ -1,7 +1,7 @@ Introduction ============ -This is GNU Bash, version 4.4. Bash is the GNU Project's Bourne +This is GNU Bash, version 5.0. Bash is the GNU Project's Bourne Again SHell, a complete implementation of the POSIX shell spec, but also with interactive command line editing, job control on architectures that support it, csh-like features such as history @@ -15,8 +15,8 @@ See the file POSIX for a discussion of how the Bash defaults differ from the POSIX spec and a description of the Bash `posix mode'. There are some user-visible incompatibilities between this version -of Bash and previous widely-distributed versions, bash-4.2 and -bash-4.3. For details, see the file COMPAT. The NEWS file tersely +of Bash and previous widely-distributed versions, bash-4.3 and +bash-4.4. For details, see the file COMPAT. The NEWS file tersely lists features that are new in this release. Bash is free software, distributed under the terms of the [GNU] General diff --git a/bashhist.c b/bashhist.c index 4cf0e4f96..e0afe52ac 100644 --- a/bashhist.c +++ b/bashhist.c @@ -780,6 +780,12 @@ check_add_history (line, force) #define OPENLOG_OPTS 0 #endif +#if defined (SYSLOG_SHOPT) +int syslog_history = SYSLOG_SHOPT; +#else +int syslog_history = 1; +#endif + void bash_syslog_history (line) const char *line; @@ -883,7 +889,8 @@ bash_add_history (line) really_add_history (line); #if defined (SYSLOG_HISTORY) - bash_syslog_history (line); + if (syslog_history) + bash_syslog_history (line); #endif using_history (); diff --git a/builtins/evalstring.c b/builtins/evalstring.c index 5073ca49a..86393cd86 100644 --- a/builtins/evalstring.c +++ b/builtins/evalstring.c @@ -435,6 +435,7 @@ parse_and_execute (string, from_file, flags) else last_result = execute_command_internal (command, 0, NO_PIPE, NO_PIPE, bitmap); + dispose_command (command); dispose_fd_bitmap (bitmap); discard_unwind_frame ("pe_dispose"); diff --git a/builtins/shopt.def b/builtins/shopt.def index 467dc5344..9b88aa446 100644 --- a/builtins/shopt.def +++ b/builtins/shopt.def @@ -121,6 +121,10 @@ extern int assoc_expand_once; extern int array_expand_once; #endif +#if defined (SYSLOG_HISTORY) && defined (SYSLOG_SHOPT) +extern int syslog_history; +#endif + static void shopt_error __P((char *)); static int set_shellopts_after_change __P((char *, int)); @@ -235,6 +239,9 @@ static struct { #endif { "shift_verbose", &print_shift_error, (shopt_set_func_t *)NULL }, { "sourcepath", &source_uses_path, (shopt_set_func_t *)NULL }, +#if defined (SYSLOG_HISTORY) && defined (SYSLOG_SHOPT) + { "syslog_history", &syslog_history, (shopt_set_func_t *)NULL }, +#endif { "xpg_echo", &xpg_echo, (shopt_set_func_t *)NULL }, { (char *)0, (int *)0, (shopt_set_func_t *)NULL } }; @@ -357,6 +364,14 @@ reset_shopt_options () command_oriented_history = 1; #endif +#if defined (SYSLOG_HISTORY) +# if defined (SYSLOG_SHOPT) + syslog_history = SYSLOG_SHOPT; +# else + syslog_history = 1; +# endif /* SYSLOG_SHOPT */ +#endif + #if defined (READLINE) complete_fullquote = 1; force_fignore = 1; diff --git a/config-top.h b/config-top.h index 3769625ba..a7008bcaf 100644 --- a/config-top.h +++ b/config-top.h @@ -124,6 +124,13 @@ # define OPENLOG_OPTS LOG_PID #endif +/* Define if you want syslogging history to be controllable at runtime via a + shell option; if defined, the value is the default for the syslog_history + shopt option */ +#if defined (SYSLOG_HISTORY) +/* #define SYSLOG_SHOPT 1 */ +#endif + /* Define if you want to include code in shell.c to support wordexp(3) */ /* #define WORDEXP_OPTION */ diff --git a/doc/bashref.texi b/doc/bashref.texi index f9f425368..c97e1175c 100644 --- a/doc/bashref.texi +++ b/doc/bashref.texi @@ -1021,7 +1021,7 @@ If the @code{nocasematch} shell option is enabled, the match is performed without regard to the case of alphabetic characters. The return value is 0 if the string matches (@samp{==}) or does not -match (@samp{!=})the pattern, and 1 otherwise. +match (@samp{!=}) the pattern, and 1 otherwise. Any part of the pattern may be quoted to force the quoted portion to be matched as a string. diff --git a/examples/loadables/Makefile.in b/examples/loadables/Makefile.in index 528ebc1d2..0facc0ba9 100644 --- a/examples/loadables/Makefile.in +++ b/examples/loadables/Makefile.in @@ -244,7 +244,7 @@ installdirs: install-dev: installdirs @$(INSTALL_DATA) Makefile.inc $(DESTDIR)$(loadablesdir)/Makefile.inc - @$(INSTALL_DATA) loadables.h $(DESTDIR)$(loadablesdir)/loadables.h + @$(INSTALL_DATA) $(srcdir)/loadables.h $(DESTDIR)$(loadablesdir)/loadables.h @( cd $(BUILD_DIR) && ${MAKE} ${MFLAGS} DESTDIR="$(DESTDIR)" install-headers) install-supported: all installdirs install-dev diff --git a/execute_cmd.c b/execute_cmd.c index 7e25b740a..ac7414fb1 100644 --- a/execute_cmd.c +++ b/execute_cmd.c @@ -1522,6 +1522,11 @@ execute_in_subshell (command, asynchronous, pipe_in, pipe_out, fds_to_close) /* Subshells are neither login nor interactive. */ login_shell = interactive = 0; + /* And we're no longer in a loop. See Posix interp 842 (we are not in the + "same execution environment"). */ + if (shell_compatibility_level > 43) + loop_level = 0; + if (user_subshell) { subshell_environment = SUBSHELL_PAREN; /* XXX */ @@ -1672,6 +1677,7 @@ execute_in_subshell (command, asynchronous, pipe_in, pipe_out, fds_to_close) return_code = (return_code == EXECUTION_SUCCESS) ? EXECUTION_FAILURE : EXECUTION_SUCCESS; + /* If we were explicitly placed in a subshell with (), we need to do the `shell cleanup' things, such as running traps[0]. */ if (user_subshell && signal_is_trapped (0)) @@ -4768,6 +4774,12 @@ execute_function (var, words, flags, fds_to_close, async, subshell) if (subshell == 0) { begin_unwind_frame ("function_calling"); + /* If the shell is in posix mode, this will push the variables in + the temporary environment to the "current shell environment" (the + global scope), and dispose the temporary env before setting it to + NULL later. This behavior has disappeared from the latest edition + of the standard, so I will eventually remove it from variables.c: + push_var_context. */ push_context (var->name, subshell, temporary_env); /* This has to be before the pop_context(), because the unwinding of local variables may cause the restore of a local declaration of diff --git a/lib/readline/readline.h b/lib/readline/readline.h index 2081b197b..4e08b2e97 100644 --- a/lib/readline/readline.h +++ b/lib/readline/readline.h @@ -39,8 +39,8 @@ extern "C" { #endif /* Hex-encoded Readline version number. */ -#define RL_READLINE_VERSION 0x0700 /* Readline 7.0 */ -#define RL_VERSION_MAJOR 7 +#define RL_READLINE_VERSION 0x0800 /* Readline 8.0 */ +#define RL_VERSION_MAJOR 8 #define RL_VERSION_MINOR 0 /* Readline data structures. */ diff --git a/po/Makefile.in.in b/po/Makefile.in.in index 673066533..5217a12ef 100644 --- a/po/Makefile.in.in +++ b/po/Makefile.in.in @@ -277,7 +277,7 @@ mostlyclean: clean: mostlyclean distclean: clean - rm -f Makefile Makefile.in POTFILES *.mo + rm -f Makefile Makefile.in POTFILES *.mo stamp-po maintainer-clean: distclean @echo "This command is intended for maintainers to use;" diff --git a/support/Makefile.in b/support/Makefile.in index f684a4d6d..0289e0acf 100644 --- a/support/Makefile.in +++ b/support/Makefile.in @@ -4,11 +4,12 @@ # documentation support: man2html # testing support: printenv recho zecho xcase # -# bashbug lives here but is created by the top-level makefile +# bashbug.sh lives here (created by configure), but bashbug is created by +# the top-level makefile # # Currently only man2html is built # -# Copyright (C) 1998-2009 Free Software Foundation, Inc. +# Copyright (C) 1998-2018 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -82,6 +83,6 @@ clean: $(RM) man2html$(EXEEXT) $(OBJ1) distclean maintainer-clean mostlyclean: clean - $(RM) bash.pc + $(RM) bash.pc bashbug.sh man2html.o: man2html.c diff --git a/tests/posixexp5.sub b/tests/posixexp5.sub index cceeb00c4..e477bbb1e 100644 --- a/tests/posixexp5.sub +++ b/tests/posixexp5.sub @@ -7,7 +7,7 @@ teststring=$(printf '\1\2\3\177') n=0 trim_od() { - od -a | sed -n '1 { s/^0*[[:blank:]]*//; s/[[:blank:]]*$//; p; }' + od -t a | sed -n '1 { s/^0*[[:blank:]]*//; s/[[:blank:]]*$//; p; }' } doTest() { diff --git a/tests/redir.right b/tests/redir.right index ab737d494..75ed45551 100644 --- a/tests/redir.right +++ b/tests/redir.right @@ -44,7 +44,7 @@ kl ab cd cd -./redir.tests: line 154: redir1.*: No such file or directory +./redir.tests: line 157: redir1.*: No such file or directory # tests of ksh93-like dup-and-close redirection operators exec 9<$0 diff --git a/tests/redir.tests b/tests/redir.tests index 7b74ac53d..6af021948 100644 --- a/tests/redir.tests +++ b/tests/redir.tests @@ -57,6 +57,9 @@ echo to c 1>&6 cat $TMPDIR/bash-c echo "Point 5" +# clean up before running scripts +exec 4>&- 5>&- 6<&- + rm -f $TMPDIR/bash-a $TMPDIR/bash-b $TMPDIR/bash-c # diff --git a/tests/test-glue-functions b/tests/test-glue-functions index b958ab71c..07ad8215f 100644 --- a/tests/test-glue-functions +++ b/tests/test-glue-functions @@ -9,5 +9,5 @@ _intl_normalize_spaces() # avoid whitespace differences in wc implementations _cut_leading_spaces() { - sed -e 's/^[[:space:]]*//g' + sed -e 's/^[ ]*//g' } diff --git a/tests/trap.right b/tests/trap.right index 78b930316..416582931 100644 --- a/tests/trap.right +++ b/tests/trap.right @@ -101,6 +101,10 @@ sleep 2 wait $! exit in trap EXIT +fn +after 1 +fn +after 2 caught a child death caught a child death caught a child death diff --git a/tests/trap.tests b/tests/trap.tests index 4176df085..637bfd282 100644 --- a/tests/trap.tests +++ b/tests/trap.tests @@ -74,6 +74,9 @@ ${THIS_SH} ./trap4.sub # This doesn't work right on all Unix versions #${THIS_SH} ./trap5.sub +# Return trap issues +${THIS_SH} ./trap6.sub + # # show that setting a trap on SIGCHLD is not disastrous. # diff --git a/tests/trap6.sub b/tests/trap6.sub new file mode 100644 index 000000000..332a17737 --- /dev/null +++ b/tests/trap6.sub @@ -0,0 +1,15 @@ +set -o functrace +fn() { return; } + +trap "echo fn ; fn" RETURN + +fn +echo after 1 + +unset -f fn + +fn() { eval return; } +fn +echo after 2 + +unset -f fn diff --git a/tests/varenv.right b/tests/varenv.right index 013017195..7ca5f6612 100644 --- a/tests/varenv.right +++ b/tests/varenv.right @@ -136,6 +136,17 @@ declare -A foo=([one]="one" [zero]="zero" ) declare -a bar=([0]="zero" [1]="one") ./varenv11.sub: line 29: a: readonly variable foo=abc +func1: var = + +func1: var = + +inside: declare -- foo +outside: +declare -x foo="abc" +inside: declare -x var="value" +outside: declare -- var="one" +inside: declare -- var="local" +outside: declare -x var="global" a=z a=b a=z diff --git a/tests/varenv.sh b/tests/varenv.sh index c15dfff67..f2299b43e 100644 --- a/tests/varenv.sh +++ b/tests/varenv.sh @@ -231,7 +231,7 @@ ${THIS_SH} ./varenv10.sub # tests of compound assignments in function scope ${THIS_SH} ./varenv11.sub -# temporary environment variable propagation in posix mode +# temporary environment variable propagation and scoping in posix mode ${THIS_SH} ./varenv12.sub # make sure variable scoping is done right diff --git a/tests/varenv12.sub b/tests/varenv12.sub index d3320b9a9..6aaf512b5 100644 --- a/tests/varenv12.sub +++ b/tests/varenv12.sub @@ -1,4 +1,62 @@ set -o posix + fn() { foo=abc : ; typeset +x foo; printenv|grep ^foo=; } fn +unset -v foo +unset -f fn + +func1() { + var=1 + var=2 : # or 'var=2 return', or another special builtin + unset -v var + echo $FUNCNAME: var = $var +} +func2() { + func1 + unset -v var # bug: fails silently +} +func1 +echo ${var+"BUG: still set 1"} + +unset var +func2 +echo ${var+"BUG: still set 2"} + +unset -v var +unset -f func1 func2 + +fn() { foo=abc : ; typeset +x foo; echo -n 'inside: ' ; declare -p foo; } +fn +echo outside: +declare -p foo + +unset -v foo +unset -f fn + +func() +{ + var=value declare -x var + echo -n 'inside: ' ; declare -p var +} + +var=one +func +echo -n 'outside: ' ; declare -p var + +unset -v var +unset -f func + +func() +{ + local var=local + var=global : + echo -n 'inside: ' ; declare -p var +} + +var=outside +func +echo -n 'outside: ' ; declare -p var + +unset -v var +unset -f func diff --git a/variables.c b/variables.c index d08e337d8..228e69a19 100644 --- a/variables.c +++ b/variables.c @@ -4889,11 +4889,22 @@ push_var_context (name, flags, tempvars) HASH_TABLE *tempvars; { VAR_CONTEXT *vc; + int posix_func_behavior; + + /* As of IEEE Std 1003.1-2017, assignment statements preceding shell + functions no longer behave like assignment statements preceding + special builtins, and do not persist in the current shell environment. + This is austin group interp #654, though nobody implements it yet. */ + posix_func_behavior = posixly_correct; /* placeholder for later */ vc = new_var_context (name, flags); - vc->table = tempvars; - if (tempvars) + /* Posix interp 1009, temporary assignments preceding function calls modify + the current environment *before* the command is executed. */ + if (posix_func_behavior && tempvars == temporary_env) + merge_temporary_env (); + else if (tempvars) { + vc->table = tempvars; /* Have to do this because the temp environment was created before variable_context was incremented. */ flatten (tempvars, set_context, (VARLIST *)NULL, 0); diff --git a/version.c b/version.c index f241c5c78..922c8d69c 100644 --- a/version.c +++ b/version.c @@ -1,6 +1,6 @@ /* version.c -- distribution and version numbers. */ -/* Copyright (C) 1989-2016 Free Software Foundation, Inc. +/* Copyright (C) 1989-2018 Free Software Foundation, Inc. This file is part of GNU Bash, the Bourne Again SHell. @@ -43,7 +43,7 @@ const char * const release_status = (char *)0; #endif const char * const sccs_version = SCCSVERSION; -const char * const bash_copyright = N_("Copyright (C) 2016 Free Software Foundation, Inc."); +const char * const bash_copyright = N_("Copyright (C) 2018 Free Software Foundation, Inc."); const char * const bash_license = N_("License GPLv3+: GNU GPL version 3 or later \n"); /* If == 31, shell compatible with bash-3.1, == 32 with bash-3.2, and so on */ diff --git a/version2.c b/version2.c index f241c5c78..922c8d69c 100644 --- a/version2.c +++ b/version2.c @@ -1,6 +1,6 @@ /* version.c -- distribution and version numbers. */ -/* Copyright (C) 1989-2016 Free Software Foundation, Inc. +/* Copyright (C) 1989-2018 Free Software Foundation, Inc. This file is part of GNU Bash, the Bourne Again SHell. @@ -43,7 +43,7 @@ const char * const release_status = (char *)0; #endif const char * const sccs_version = SCCSVERSION; -const char * const bash_copyright = N_("Copyright (C) 2016 Free Software Foundation, Inc."); +const char * const bash_copyright = N_("Copyright (C) 2018 Free Software Foundation, Inc."); const char * const bash_license = N_("License GPLv3+: GNU GPL version 3 or later \n"); /* If == 31, shell compatible with bash-3.1, == 32 with bash-3.2, and so on */ -- 2.47.2