]> git.ipfire.org Git - thirdparty/bash.git/commitdiff
fix for nofork comsubs undoing enclosing command's redirections; fix for binding...
authorChet Ramey <chet.ramey@case.edu>
Wed, 20 Aug 2025 15:08:28 +0000 (11:08 -0400)
committerChet Ramey <chet.ramey@case.edu>
Wed, 20 Aug 2025 15:08:28 +0000 (11:08 -0400)
21 files changed:
CWRU/CWRU.chlog
MANIFEST
arrayfunc.c
execute_cmd.c
lib/readline/isearch.c
lib/readline/rlprivate.h
lib/readline/signals.c
parse.y
subst.c
tests/glob2.sub
tests/history7.sub
tests/intl.tests
tests/intl3.sub
tests/nameref.right
tests/nquote3.sub
tests/nquote5.sub
tests/posixpipe.tests
tests/procsub.tests
tests/test-aux-functions [new file with mode: 0644]
tests/unicode2.sub
variables.h

index fc2b78c5fe93857be50c658102f2a4598b8660fd..7d0ececa7d6d8695e21d5c0c0b3dbdbeab0a1daf 100644 (file)
@@ -11586,3 +11586,42 @@ builtins/declare.def
          an invalid value for a nameref variable, but the original value is
          valid, add an error message for the assignment error
          Report from Oğuz <oguzismailuysal@gmail.com>
+
+                                  8/12
+                                  ----
+subst.c
+       - function_substitute: unwind-protect redirection_undo_list and
+         exec_redirection_undo_list so the funsub command doesn't undo them
+         prematurely
+         Report from jdhedden@gmail.com
+
+                                  8/13
+                                  ----
+execute_cmd.c
+       - bind_lastarg: don't try to bind the argument in the temporary
+         environment; just skip that and bind in the closest enclosing
+         scope
+         Report from Nathan Mills <the.true.nathan.mills@gmail.com>
+
+                                  8/15
+                                  ----
+arrayfunc.c
+       - convert_var_to_array,convert_var_to_assoc: call
+         stupidly_hack_special_variables to clean up any state associated
+         with the variable (e.g., IFS).
+         Report from Nathan Mills <the.true.nathan.mills@gmail.com>
+
+subst.c
+       - setifs: if a script attempts to make IFS an array variable, use
+         element 0 or "0" as appropriate.
+         Report from Nathan Mills <the.true.nathan.mills@gmail.com>
+
+                                  8/19
+                                  ----
+lib/readline/isearch.c
+       - _rl_isearch_cleanup: to avoid problems caused by calling this from
+         normal isearch termination and from signal cleanup code, turn off
+         the RL_STATE_ISEARCH flag and set _rl_iscxt to NULL before doing
+         anything else that would cause signals to be processed.
+         Report and fix from Grisha Levit <grishalevit@gmail.com> based on
+         a report from penguin p <tgckpg@gmail.com>
index 78143bc872a4de0638adcc331a77fd423b2ba26c..5c084e57726da1191e992c3e47a4c4e6e808553c 100644 (file)
--- a/MANIFEST
+++ b/MANIFEST
@@ -942,7 +942,7 @@ examples/shellmath/testCases.in     f
 examples/shellmath/timingData.txt      f
 tests/README           f
 tests/COPYRIGHT                f
-tests/test-glue-functions      f
+tests/test-aux-functions       f
 tests/alias.tests      f
 tests/alias1.sub       f
 tests/alias2.sub       f
index 715460d59904e234651301a051554106b9cd5b14..33000f71a264c4f73b9ba4ae27724775e1d90473 100644 (file)
@@ -102,6 +102,7 @@ convert_var_to_array (SHELL_VAR *var)
   /* Since namerefs can't be array variables, turn off nameref attribute */
   VUNSETATTR (var, att_nameref);
 
+  stupidly_hack_special_variables (var->name);
   return var;
 }
 
@@ -139,6 +140,7 @@ convert_var_to_assoc (SHELL_VAR *var)
   /* Since namerefs can't be array variables, turn off nameref attribute */
   VUNSETATTR (var, att_nameref);
 
+  stupidly_hack_special_variables (var->name);
   return var;
 }
 
index 9421484141bcb137c09e54a5bd4fb2387d02dd74..a68c5a1fd1db3cb8b39fb13c6411a362109965e5 100644 (file)
@@ -4156,7 +4156,7 @@ bind_lastarg (char *arg)
 
   if (arg == 0)
     arg = "";
-  var = bind_variable ("_", arg, 0);
+  var = bind_variable ("_", arg, ASS_NOTEMPENV);
   if (var)
     VUNSETATTR (var, att_exported);
 }
index 7b845c20dc7d03808582b6998a1aacb4b4ef695c..6cb1879d2b687062c086c05725ee75789d142916 100644 (file)
@@ -889,12 +889,14 @@ opcode_dispatch:
 int
 _rl_isearch_cleanup (_rl_search_cxt *cxt, int r)
 {
+  RL_UNSETSTATE(RL_STATE_ISEARCH);
+  if (cxt == 0)
+    return (r != 0);
+
+  _rl_iscxt = 0;
   if (r >= 0)
     _rl_isearch_fini (cxt);
   _rl_scxt_dispose (cxt, 0);
-  _rl_iscxt = 0;
-
-  RL_UNSETSTATE(RL_STATE_ISEARCH);
 
   return (r != 0);
 }
index eb0495f9be5914129233da2988142283eb0bfbda..c8cb6736f252d320dba4a771eff7465935c5f914 100644 (file)
@@ -446,8 +446,10 @@ extern void _rl_signal_handler (int);
 
 extern void _rl_block_sigint (void);
 extern void _rl_release_sigint (void);
+extern int _rl_sigint_blocked_p (void);
 extern void _rl_block_sigwinch (void);
 extern void _rl_release_sigwinch (void);
+extern int _rl_sigwinch_blocked_p (void);
 
 extern void _rl_state_sigcleanup (void);
 
index 5a070d774614483b5ef0f602929ee76e3eb3d7ef..73ae5670f3ace2545b3a4d98cebd333bed3dbe9f 100644 (file)
@@ -680,6 +680,12 @@ _rl_release_sigint (void)
     RL_CHECK_SIGNALS ();
 }
 
+int
+_rl_sigint_blocked_p (void)
+{
+  return sigint_blocked;
+}
+
 /* Cause SIGWINCH to not be delivered until the corresponding call to
    release_sigwinch(). */
 void
@@ -736,6 +742,12 @@ _rl_release_sigwinch (void)
   sigwinch_blocked = 0;
 }
 
+int
+_rl_sigwinch_blocked_p (void)
+{
+  return sigwinch_blocked;
+}
+
 /* **************************************************************** */
 /*                                                                 */
 /*             Echoing special control characters                  */
diff --git a/parse.y b/parse.y
index 462953b7d00240405f75b7d275d2283d90fb53f0..b698f86bc7f2863430cbad6d2371d2978b601dff 100644 (file)
--- a/parse.y
+++ b/parse.y
@@ -2500,6 +2500,8 @@ shell_getc (int remove_quoted_newline)
      something on the pushed list of strings, then we don't want to go
      off and get another line.  We let the code down below handle it. */
 
+  /* If we're reading input from the keyboard or from a file, fetch
+     another line from the current source. */
   if (!shell_input_line || ((!shell_input_line[shell_input_line_index]) &&
                            (pushed_string_list == (STRING_SAVER *)NULL)))
 #else /* !ALIAS && !DPAREN_ARITHMETIC */
@@ -2741,11 +2743,11 @@ shell_getc (int remove_quoted_newline)
             going to be removing quoted newlines, since that will eat the
             backslash.  Add another backslash instead (will be removed by
             word expansion). */
-         if (bash_input.type == st_string && expanding_alias() == 0 && last_was_backslash && c == EOF && remove_quoted_newline)
+         if (bash_input.type == st_string && expanding_alias () == 0 && last_was_backslash && c == EOF && remove_quoted_newline)
            shell_input_line[shell_input_line_len] = '\\';
-         else if (bash_input.type == st_bstream && expanding_alias() == 0 && last_was_backslash && c == EOF && remove_quoted_newline)
+         else if (bash_input.type == st_bstream && expanding_alias () == 0 && last_was_backslash && c == EOF && remove_quoted_newline)
            shell_input_line[shell_input_line_len] = '\\';
-         else if (interactive == 0 && bash_input.type == st_stream && expanding_alias() == 0 && last_was_backslash && c == EOF && remove_quoted_newline)
+         else if (interactive == 0 && bash_input.type == st_stream && expanding_alias () == 0 && last_was_backslash && c == EOF && remove_quoted_newline)
            shell_input_line[shell_input_line_len] = '\\';
          else
            shell_input_line[shell_input_line_len] = '\n';
@@ -2905,6 +2907,18 @@ pop_alias:
       shell_input_line_index = 0;
       goto restart_read;
     }
+
+#if 0  /*TAG:bash-5.4 wyeth2485@gmail.com 8/15/2025 */
+  /* When we're reading input from a string, we don't increment line_number
+     until now. If we're being called from read_token_word(), this will be
+     pushed back into the input string with shell_ungetc for the next call
+     to read_token() to consume. We don't want to increment line_number
+     twice, so this requires cooperation from shell_ungetc (decrement
+     line_number if we're pushing back a newline while parsing an alias
+     expansion). */
+  if (uc == '\n' && expanding_alias () && pushed_string_list->flags == PSH_ALIAS)
+    line_number++;
+#endif
 #endif
 
   return (uc);
@@ -2922,6 +2936,11 @@ shell_ungetc (int c)
     shell_input_line[--shell_input_line_index] = c;
   else
     eol_ungetc_lookahead = c;
+
+#if 0  /*TAG:bash-5.4 wyeth2485@gmail.com 8/15/2025 */
+  if (c == '\n' && expanding_alias () && heredoc_string == 0 && line_number > 0)
+    line_number--;
+#endif
 }
 
 /* Push S back into shell_input_line; updating shell_input_line_index */
diff --git a/subst.c b/subst.c
index 3be17a85974bf52739653fcb0664ce2473d095be..fd7262a4243a4c163801994d02cabe70c5fd4fd3 100644 (file)
--- a/subst.c
+++ b/subst.c
@@ -206,6 +206,8 @@ extern int wordexp_only;
 extern int singlequote_translations;
 extern int extended_quote;
 
+extern REDIRECT *exec_redirection_undo_list, *redirection_undo_list;
+
 #if !defined (HAVE_WCSDUP) && defined (HANDLE_MULTIBYTE)
 extern wchar_t *wcsdup (const wchar_t *);
 #endif
@@ -7022,7 +7024,12 @@ function_substitute (char *string, int quoted, int flags)
       add_unwind_protect (uw_restore_pipestatus_array, psa);
     }
 #endif
-  
+
+  unwind_protect_pointer (redirection_undo_list);
+  redirection_undo_list = NULL;
+  unwind_protect_pointer (exec_redirection_undo_list);
+  exec_redirection_undo_list = NULL;
+
   subst_assign_varlist = 0;
 
   temporary_env = 0;
@@ -12358,11 +12365,15 @@ word_list_quote_removal (WORD_LIST *list, int quoted)
 void
 setifs (SHELL_VAR *v)
 {
-  char *t;
+  char *t, *value;
   unsigned char uc;
 
   ifs_var = v;
-  ifs_value = (v && value_cell (v)) ? value_cell (v) : " \t\n";
+  /* If we do not want to support IFS as an array variable here, check that
+     V is not an array (array_p(v) == 0 && assoc_p (v) == 0) as part of the
+     test to call get_variable_value and set VALUE to NULL if it is. */
+  value = v ? get_variable_value (v) : (char *)NULL;
+  ifs_value = (v && value) ? value : " \t\n";
 
   ifs_is_set = ifs_var != 0;
   ifs_is_null = ifs_is_set && (*ifs_value == 0);
index 0e0482dca98162da808dfee23fd88fc90743d368..c52637750ee50a4c322897ba750a79ba0591f150 100644 (file)
@@ -11,7 +11,7 @@
 #   You should have received a copy of the GNU General Public License
 #   along with this program.  If not, see <http://www.gnu.org/licenses/>.
 #
-. ./test-glue-functions
+. ./test-aux-functions
 
 # this locale causes problems all over the place
 if locale -a | grep -i '^zh_TW\.big5' >/dev/null ; then
index 9c9d27b4b5a9e07aa7d0aa04e5232b33c3161620..cbb233812c5606942b8735ae3c0768d976e18afc 100644 (file)
@@ -12,7 +12,7 @@
 #   along with this program.  If not, see <http://www.gnu.org/licenses/>.
 #
 # test history file truncation for various values of $HISTFILESIZE
-. ./test-glue-functions
+. ./test-aux-functions
 
 : ${THIS_SH:=./bash}
 : ${TMPDIR:=/var/tmp}
index 990d782dd0d202f65b602e14e590b2925f0ca695..2a4b26e0e1e32373b6dd807e9bb100e1c4e5b10a 100644 (file)
@@ -49,7 +49,7 @@ set a b
 
 printf '%s\n' "$*"
 
-. ./test-glue-functions
+. ./test-aux-functions
 
 printf '%s' "$*" | od -b | _intl_normalize_spaces
 
index 56c867807125b22b291db0f2e90b6df0896bff85..b4d571edf740124e7a28b5a3a96c620b6ffccd81 100644 (file)
@@ -11,7 +11,7 @@
 #   You should have received a copy of the GNU General Public License
 #   along with this program.  If not, see <http://www.gnu.org/licenses/>.
 #
-. ./test-glue-functions
+. ./test-aux-functions
 
 # more tests to make sure that IFS splits on characters, not bytes
 export LANG=en_US.UTF-8
index af86df5208df576f5a3adc1d751a773522984117..ad0fdac749e392ad99fbe3001c8c3eecc466091f 100644 (file)
@@ -534,6 +534,7 @@ declare -a array=([0]="one" [1]="two" [2]="three")
 declare -ai a=([0]="5")
 declare -ai a=([0]="6")
 declare -ai a=([0]="42")
+./nameref23.sub: line 28: declare: a[0]: expands to invalid variable name for name reference
 declare -ai a=([0]="1")
 ./nameref23.sub: line 29: declare: b: not found
 declare -ai a=([0]="1")
index d1480c0bfbc7b5eaa7152d65581590c73b4e118d..cfec48b51c7a81b151cf96f97572e0604e7dddd3 100644 (file)
@@ -1,4 +1,4 @@
-. ./test-glue-functions
+. ./test-aux-functions
 
 recho $'\c?'
 
index 97cbadc417c11297584c283ccaf4d2c646115fee..f5b928d1f1bf4caed9f594576848e3f34556c844 100644 (file)
@@ -11,7 +11,7 @@
 #   You should have received a copy of the GNU General Public License
 #   along with this program.  If not, see <http://www.gnu.org/licenses/>.
 #
-. test-glue-functions
+. test-aux-functions
 
 recho $( echo a$'\01)'b )
 recho $( echo a\ 1b )
index 3fe5f770be66f01142fad4018e7c2aa8710456ec..c4eca6cc2a09195d9f8625ffde54da60355b9b88 100644 (file)
@@ -58,6 +58,6 @@ time -p -- echo a
 time -- :
 
 # this should print timing information
-. ./test-glue-functions
+. ./test-aux-functions
 
 ${THIS_SH} -c '{ time; echo after; }' |& wc -l | _cut_leading_spaces
index 946d2c2269ee4652072abebaafe5c3821c330afd..140f6e70c85dc8b8f352d7d1622bce8f9871583b 100644 (file)
@@ -12,7 +12,7 @@
 #   along with this program.  If not, see <http://www.gnu.org/licenses/>.
 #
 # process substitution constructs that have caused problems in the past
-. ./test-glue-functions
+. ./test-aux-functions
 
 eval cat <(echo test1)
 eval "echo foo;cat" <(echo test2)
diff --git a/tests/test-aux-functions b/tests/test-aux-functions
new file mode 100644 (file)
index 0000000..2423eeb
--- /dev/null
@@ -0,0 +1,21 @@
+# shell functions to include in multiple test files
+
+# squeeze out blanks to avoid white space differences in od implementations
+_intl_normalize_spaces()
+{
+       sed -e 's/[[:space:]]\{1,\}/ /g' -e 's/[[:space:]]*$//'
+}
+
+# avoid whitespace differences in wc implementations
+_cut_leading_spaces()
+{
+       sed -e 's/^[    ]*//g'
+}
+
+test_runsub()
+{
+       scriptname=${1##*/}
+       printf '\t%s\n' "${scriptname}"
+
+       ${THIS_SH} "$1"
+}
index 16dd604ac34dba1700aa2e069ff49fda67a9e390..b98ac7c46a9a8a0744f58f7fd35f2947b44cc9c4 100644 (file)
@@ -11,7 +11,7 @@
 #   You should have received a copy of the GNU General Public License
 #   along with this program.  If not, see <http://www.gnu.org/licenses/>.
 #
-. ./test-glue-functions
+. ./test-aux-functions
 
 export LANG=en_US.UTF-8
 
index f098cce178bb9b1c1de0a9fbee386bf36785bb9b..5e870986e93d514b0516d47f1906e1204c6c7b63 100644 (file)
@@ -173,6 +173,8 @@ typedef struct _vlist {
 #define tempvar_p(var)         ((((var)->attributes) & (att_tempvar)))
 #define propagate_p(var)       ((((var)->attributes) & (att_propagate)))
 
+#define assigning_p(var)       ((((var)->attributes) & (att_assigning)))
+
 /* Variable names: lvalues */
 #define name_cell(var)         ((var)->name)