]> git.ipfire.org Git - thirdparty/bash.git/commitdiff
fix for too-aggressive optimizing forks away in an `eval' command inside a (command...
authorChet Ramey <chet.ramey@case.edu>
Mon, 21 Nov 2022 16:43:19 +0000 (11:43 -0500)
committerChet Ramey <chet.ramey@case.edu>
Mon, 21 Nov 2022 16:43:19 +0000 (11:43 -0500)
CWRU/CWRU.chlog
builtins/common.h
builtins/eval.def
builtins/evalstring.c
doc/bashref.texi
doc/version.texi
jobs.c
lib/readline/readline.c
parse.y
trap.c

index 94ed6c46f7b3d627deee5c20017d29438cce0ad8..ba9d673390d7c06d71f3b64b03307dffdcc4f0de 100644 (file)
@@ -4466,3 +4466,32 @@ lib/glob/sm_loop.c
          Updates from Koichi Murase <myoga.murase@gmail.com>
        - BRACKMATCH: if a range expression is incomplete (no end char),
          treat the bracket as an ordinary character
+
+                                  11/18
+                                  -----
+doc/bashref.texi
+       - Reporting Bugs: add mention of the Savannah project page. Suggested
+         by Loïc Yhuel <loic.yhuel@gmail.com>
+
+                                  11/20
+                                  -----
+builtins/common.h
+       - SEVAL_NOOPTIMIZE: new flag for parse_and_execute: means don't try to
+         optimize forks out of any simple or conditional commands
+
+builtins/evalstring.c
+       - parse_and_execute: if FLAGS includes SEVAL_NOOPTIMIZE, don't try to
+         call can_optimize_connection to optimize away forks from AND_AND or
+         OR_OR commands
+
+builtins/eval.def,trap.c,parse.y,jobs.c
+       - parse_and_execute: include SEVAL_NOOPTIMIZE in any calls to
+         parse_and_execute. Fixes bug reported by
+         Frode Nordahl <frode.nordahl@canonical.com>
+
+                                  11/21
+                                  -----
+lib/readline/readline.c
+       - readline_initialize_everything: use xmalloc to initialize
+         rl_executing_keyseq, since we use xrealloc to reallocate it and
+         don't check it for NULL anywhere
index 726bd91fc37aec3fa8010dc4b2f213ea120337b8..a170f8fcff1fb6d96c58790216b0df1eb012bf40 100644 (file)
@@ -51,6 +51,7 @@ do { \
 #define SEVAL_FUNCDEF  0x080           /* only allow function definitions */
 #define SEVAL_ONECMD   0x100           /* only allow a single command */
 #define SEVAL_NOHISTEXP        0x200           /* inhibit history expansion */
+#define SEVAL_NOOPTIMIZE 0x400         /* don't try to set optimization flags */
 
 /* Flags for describe_command, shared between type.def and command.def */
 #define CDESC_ALL              0x001   /* type -a */
index a92b538f26bd8f01bfbbceb369a173dfce3f9c7f..f459bce34a6e4a80399356f389e494fcce330f85 100644 (file)
@@ -53,5 +53,5 @@ eval_builtin (list)
     return (EX_USAGE);
   list = loptend;      /* skip over possible `--' */
 
-  return (list ? evalstring (string_list (list), "eval", SEVAL_NOHIST) : EXECUTION_SUCCESS);
+  return (list ? evalstring (string_list (list), "eval", SEVAL_NOHIST|SEVAL_NOOPTIMIZE) : EXECUTION_SUCCESS);
 }
index 30aa8c6427e131ba7361c6fdca128e44cb6c3d00..1bb630e4e9650b03bc5cb7b3bc40a2c55e36fbf0 100644 (file)
@@ -132,8 +132,8 @@ optimize_connection_fork (command)
   if (command->type == cm_connection &&
       (command->value.Connection->connector == AND_AND || command->value.Connection->connector == OR_OR || command->value.Connection->connector == ';') &&
       (command->value.Connection->second->flags & CMD_TRY_OPTIMIZING) &&
-      ((startup_state == 2 && should_suppress_fork (command->value.Connection->second)) ||
-       ((subshell_environment & SUBSHELL_PAREN) && should_optimize_fork (command->value.Connection->second, 0))))
+      (should_suppress_fork (command->value.Connection->second) ||
+      ((subshell_environment & SUBSHELL_PAREN) && should_optimize_fork (command->value.Connection->second, 0))))
     {
       command->value.Connection->second->flags |= CMD_NO_FORK;
       command->value.Connection->second->value.Simple->flags |= CMD_NO_FORK;
@@ -290,6 +290,7 @@ parse_prologue (string, flags, tag)
        (flags & SEVAL_NOFREE) -> don't free STRING when finished
        (flags & SEVAL_RESETLINE) -> reset line_number to 1
        (flags & SEVAL_NOHISTEXP) -> history_expansion_inhibited -> 1
+       (flags & SEVAL_NOOPTIMIZE) -> don't try to turn on optimizing flags
 */
 
 int
@@ -502,7 +503,9 @@ parse_and_execute (string, from_file, flags)
                 if we are at the end of the command string, the last in a
                 series of connection commands is
                 command->value.Connection->second. */
-             else if (command->type == cm_connection && can_optimize_connection (command))
+             else if (command->type == cm_connection &&
+                      (flags & SEVAL_NOOPTIMIZE) == 0 &&
+                      can_optimize_connection (command))
                {
                  command->value.Connection->second->flags |= CMD_TRY_OPTIMIZING;
                  command->value.Connection->second->value.Simple->flags |= CMD_TRY_OPTIMIZING;
index b0dc2fad11723a1725fbb5eb5a18a8421fb1973b..e210647549fa1a5a903d03ecf2a50c4ef1dfc2de 100644 (file)
@@ -2163,7 +2163,7 @@ introduce indirection.
 In each of the cases below, @var{word} is subject to tilde expansion,
 parameter expansion, command substitution, and arithmetic expansion.
 
-When not performing substring expansion, using the form described
+When not performing substring expansion, using the forms described
 below (e.g., @samp{:-}), Bash tests for a parameter that is unset or null.
 Omitting the colon results in a test only for a parameter that is unset.
 Put another way, if the colon is included,
@@ -9592,11 +9592,11 @@ The latest version of Bash is always available for FTP from
 @uref{http://git.savannah.gnu.org/cgit/bash.git/snapshot/bash-master.tar.gz}.
 
 Once you have determined that a bug actually exists, use the
-@code{bashbug} command to submit a bug report.
-If you have a fix, you are encouraged to mail that as well!
+@code{bashbug} command to submit a bug report or use the form at the
+<a href="https://savannah.gnu.org/projects/bash/">Bash project page</a>.
+If you have a fix, you are encouraged to submit that as well!
 Suggestions and `philosophical' bug reports may be mailed
-to @email{bug-bash@@gnu.org} or posted to the Usenet
-newsgroup @code{gnu.bash.bug}.
+to @email{bug-bash@@gnu.org} or @email{help-bash@gnu.org}.
 
 All bug reports should include:
 @itemize @bullet
index 175aa07a9418941295738996ee71a134c7512599..08c7a33aaeb1dfc0e30b298bbac722101e56d43d 100644 (file)
@@ -2,10 +2,10 @@
 Copyright (C) 1988-2022 Free Software Foundation, Inc.
 @end ignore
 
-@set LASTCHANGE Mon Sep 19 11:13:51 EDT 2022
+@set LASTCHANGE Fri Nov 18 11:09:41 EST 2022
 
 @set EDITION 5.2
 @set VERSION 5.2
 
-@set UPDATED 19 September 2022
-@set UPDATED-MONTH September 2022
+@set UPDATED 18 November 2022
+@set UPDATED-MONTH November 2022
diff --git a/jobs.c b/jobs.c
index 03a9605302668a13cf99e68f07f8e99ae2570171..76d60315c248072096adbcd2c0b5c5b0cbe8b0dc 100644 (file)
--- a/jobs.c
+++ b/jobs.c
@@ -4242,7 +4242,7 @@ run_sigchld_trap (nchild)
   jobs_list_frozen = 1;
   for (i = 0; i < nchild; i++)
     {
-      parse_and_execute (savestring (trap_command), "trap", SEVAL_NOHIST|SEVAL_RESETLINE);
+      parse_and_execute (savestring (trap_command), "trap", SEVAL_NOHIST|SEVAL_RESETLINE|SEVAL_NOOPTIMIZE);
     }
 
   run_unwind_frame ("SIGCHLD trap");
index b58a785294168fc9e053216281dd6da067989c8f..4c8a05d38e5d3258b1b848b585a3ada48907a59d 100644 (file)
@@ -1327,9 +1327,8 @@ readline_initialize_everything (void)
     _rl_parse_colors ();
 #endif
 
-  rl_executing_keyseq = malloc (_rl_executing_keyseq_size = 16);
-  if (rl_executing_keyseq)
-    rl_executing_keyseq[rl_key_sequence_length = 0] = '\0';
+  rl_executing_keyseq = xmalloc (_rl_executing_keyseq_size = 16);
+  rl_executing_keyseq[rl_key_sequence_length = 0] = '\0';
 }
 
 /* If this system allows us to look at the values of the regular
diff --git a/parse.y b/parse.y
index 4f5b84a753f6ce16c9c6094d970b6923a1b13a93..cdba786cadb1bec7f96048cda26797337c4324f5 100644 (file)
--- a/parse.y
+++ b/parse.y
@@ -2843,7 +2843,7 @@ execute_variable_command (command, vname)
   if (last_lastarg)
     last_lastarg = savestring (last_lastarg);
 
-  parse_and_execute (savestring (command), vname, SEVAL_NONINT|SEVAL_NOHIST);
+  parse_and_execute (savestring (command), vname, SEVAL_NONINT|SEVAL_NOHIST|SEVAL_NOOPTIMIZE);
 
   restore_parser_state (&ps);
   bind_variable ("_", last_lastarg, 0);
diff --git a/trap.c b/trap.c
index 8d94dcd3a81ffa15f80b533b6bb1f4e85ef4e9fe..ddd539017d7fbf4ac624a90f5680c31a16b6fd04 100644 (file)
--- a/trap.c
+++ b/trap.c
@@ -453,7 +453,7 @@ run_pending_traps ()
 
              if (function_code == 0)
                /* XXX is x always last_command_exit_value? */
-               x = parse_and_execute (trap_command, "trap", SEVAL_NONINT|SEVAL_NOHIST|SEVAL_RESETLINE);
+               x = parse_and_execute (trap_command, "trap", SEVAL_NONINT|SEVAL_NOHIST|SEVAL_RESETLINE|SEVAL_NOOPTIMIZE);
              else
                {
                  parse_and_execute_cleanup (sig + 1);  /* XXX - could use -1 */
@@ -1017,7 +1017,7 @@ run_exit_trap ()
       if (code == 0 && function_code == 0)
        {
          reset_parser ();
-         parse_and_execute (trap_command, "exit trap", SEVAL_NONINT|SEVAL_NOHIST|SEVAL_RESETLINE);
+         parse_and_execute (trap_command, "exit trap", SEVAL_NONINT|SEVAL_NOHIST|SEVAL_RESETLINE|SEVAL_NOOPTIMIZE);
        }
       else if (code == ERREXIT)
        retval = last_command_exit_value;
@@ -1130,7 +1130,7 @@ _run_trap_internal (sig, tag)
          function_code = setjmp_nosigs (return_catch);
        }
 
-      flags = SEVAL_NONINT|SEVAL_NOHIST;
+      flags = SEVAL_NONINT|SEVAL_NOHIST|SEVAL_NOOPTIMIZE;
       if (sig != DEBUG_TRAP && sig != RETURN_TRAP && sig != ERROR_TRAP)
        flags |= SEVAL_RESETLINE;
       if (function_code == 0)