]> git.ipfire.org Git - thirdparty/bash.git/commitdiff
fix crash with unset arrays in arithmetic constructs ; change to avoid printing foreg...
authorChet Ramey <chet.ramey@case.edu>
Tue, 4 Oct 2022 15:58:54 +0000 (11:58 -0400)
committerChet Ramey <chet.ramey@case.edu>
Tue, 4 Oct 2022 15:58:54 +0000 (11:58 -0400)
CWRU/CWRU.chlog
builtins/wait.def
configure
execute_cmd.c
jobs.c
lib/readline/input.c
m4/strtoimax.m4
subst.c
tests/array.right
tests/array27.sub

index 967239559fdbe1c73c6c1448f5a40c08a9294e31..c5286520f8ec76c5ebc0cf4010f68d2a9d77e373 100644 (file)
@@ -3990,3 +3990,33 @@ lib/sh/{mbscasecmp,mbscmp}.c
        - mbscasecmp,mbscmp: use different mbstate_t objects for the different
          strings so they don't affect each others' intermediate mbstate.
          From Koichi Murase <myoga.murase@gmail.com>
+
+                                  9/28
+                                  ----
+execute_cmd.c
+       - execute_command_internal: if executing a (command) subshell, restore
+         the value of line_number from save_line_number before returning early
+         due to being a non-terminal pipeline element.
+         From https://savannah.gnu.org/support/index.php?110714
+
+                                  9/30
+                                  ----
+subst.c
+       - expand_array_subscript: make sure to pass a non-NULL first argument
+         to sh_backslash_quote. Report from Emanuele Torre <torreemanuele6@gmail.com>,
+         patch from Koichi Murase <myoga.murase@gmail.com>
+
+                                  9/30
+                                  ----
+jobs.c
+       - cleanup_dead_jobs: delete dead foreground jobs we won't notify the
+         user about (those not killed by a signal or killed by SIGINT/SIGPIPE).
+         From a report from Koichi Murase <myoga.murase@gmail.com>
+       - wait_for_any_job: never return a foreground job, even when requested
+         by pid, if it's in the jobs list
+         Report and fix from Koichi Murase <myoga.murase@gmail.com>
+
+m4/strtoimax.m4
+       - BASH_FUNC_STRTOIMAX: fix logic inversion of result; we should be
+         replacing the function if the tests show we *don't* have a working
+         version. Report from Emanuel Haupt <ehaupt@FreeBSD.org>
index b066d78d0e5145dfd1bbbffa40cbb32c061bd74e..1a49430a39e17791e68474948572495cc982b82b 100644 (file)
@@ -1,4 +1,4 @@
-'This file is wait.def, from which is created wait.c.
+This file is wait.def, from which is created wait.c.
 It implements the builtin "wait" in Bash.
 
 Copyright (C) 1987-2021 Free Software Foundation, Inc.
index 28e09134992d85d81e603dfecb7a55755096a378..0c3ef2cb2c7c79f2db3503e40b395f5548de7398 100755 (executable)
--- a/configure
+++ b/configure
@@ -20432,7 +20432,6 @@ printf "%s\n" "#define HAVE_DECL_STRTOIMAX $ac_have_decl" >>confdefs.h
   if test "$ac_cv_have_decl_strtoimax" = "yes" ; then
     HAVE_DECL_STRTOIMAX=1
   fi
-
   if test "$HAVE_STRTOIMAX" = 0 || test "$HAVE_DECL_STRTOIMAX" = 0 ; then
     bash_cv_func_strtoimax=no REPLACE_STRTOIMAX=1
   else
 
 { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $bash_cv_func_strtoimax" >&5
 printf "%s\n" "$bash_cv_func_strtoimax" >&6; }
-if test $bash_cv_func_strtoimax = yes; then
+if test "$ac_cv_have_decl_strtoimax" = "yes" ; then
+printf "%s\n" "#define HAVE_DECL_STRTOIMAX 1" >>confdefs.h
+
+fi
+if test $bash_cv_func_strtoimax = no; then
 case " $LIBOBJS " in
   *" strtoimax.$ac_objext "* ) ;;
   *) LIBOBJS="$LIBOBJS strtoimax.$ac_objext"
index e5c6b9ab79431b248ac4b3c1ddcb7ad7a657980f..b62f910508971865519ef23de66fb48e65cd267d 100644 (file)
@@ -648,6 +648,7 @@ execute_command_internal (command, asynchronous, pipe_in, pipe_out,
       save_line_number = line_number;
       if (command->type == cm_subshell)
        SET_LINE_NUMBER (command->value.Subshell->line);        /* XXX - save value? */
+
        /* Otherwise we defer setting line_number */
       tcmd = make_command_string (command);
       fork_flags = asynchronous ? FORK_ASYNC : 0;
@@ -690,6 +691,10 @@ execute_command_internal (command, asynchronous, pipe_in, pipe_out,
          if (variable_context == 0)    /* wait until shell function completes */
            unlink_fifo_list ();
 #endif
+
+         /* Restore any saved state here before possible early return. */
+         line_number = save_line_number;
+
          /* If we are part of a pipeline, and not the end of the pipeline,
             then we should simply return and let the last command in the
             pipe be waited for.  If we are not in a pipeline, or are the
@@ -700,8 +705,6 @@ execute_command_internal (command, asynchronous, pipe_in, pipe_out,
 
          stop_pipeline (asynchronous, (COMMAND *)NULL);
 
-         line_number = save_line_number;
-
          if (asynchronous == 0)
            {
              was_error_trap = signal_is_trapped (ERROR_TRAP) && signal_is_ignored (ERROR_TRAP) == 0;
diff --git a/jobs.c b/jobs.c
index 6b986ed76ace7e249198d61c04aff6da26f02823..f7112627aa0421a17a33e40557109121fdf090ad 100644 (file)
--- a/jobs.c
+++ b/jobs.c
@@ -270,6 +270,8 @@ static int set_job_status_and_cleanup PARAMS((int));
 static WAIT job_signal_status PARAMS((int));
 static WAIT raw_job_exit_status PARAMS((int));
 
+static int job_killed_by_signal PARAMS((int));
+
 static void notify_of_job_status PARAMS((void));
 static void reset_job_indices PARAMS((void));
 static void cleanup_dead_jobs PARAMS((void));
@@ -1226,8 +1228,12 @@ cleanup_dead_jobs ()
       if (i > js.j_lastj && jobs[i])
        INTERNAL_DEBUG(("cleanup_dead_jobs: job %d non-null after js.j_lastj (%d)", i, js.j_lastj));
 
-      if (jobs[i] && DEADJOB (i) && IS_NOTIFIED (i))
-       delete_job (i, 0);
+      if (jobs[i] == 0 || DEADJOB (i) == 0)
+       continue;               /* not a candidate */
+      else if (IS_NOTIFIED (i))
+       delete_job (i, 0);      /* already notified */
+      else if (IS_FOREGROUND (i) && job_killed_by_signal (i) == 0)
+       delete_job (i, 0);      /* we won't notify about this */
     }
 
 #if defined (PROCESS_SUBSTITUTION)
@@ -2876,6 +2882,20 @@ job_exit_signal (job)
   return (process_exit_signal (raw_job_exit_status (job)));
 }
 
+static int
+job_killed_by_signal (job)
+     int job;
+{
+  int termsig;
+
+  termsig = job_exit_signal (job);
+#if !defined (DONT_REPORT_SIGPIPE)
+  return (termsig && termsig != SIGINT);
+#else
+  return (termsig && termsig != SIGINT && termsig != SIGPIPE);
+#endif
+}
+
 #define FIND_CHILD(pid, child) \
   do \
     { \
@@ -3283,7 +3303,7 @@ wait_for_any_job (flags, ps)
     {
       if ((flags & JWAIT_WAITING) && jobs[i] && IS_WAITING (i) == 0)
        continue;               /* if we don't want it, skip it */
-      if (jobs[i] && DEADJOB (i) && IS_NOTIFIED (i) == 0)
+      if (jobs[i] && DEADJOB (i) && IS_NOTIFIED (i) == 0 && IS_FOREGROUND (i) == 0)
        {
 return_job:
          r = job_exit_status (i);
@@ -4318,6 +4338,7 @@ notify_of_job_status ()
                  if (termsig && WIFSIGNALED (s) && termsig != SIGINT && termsig != SIGPIPE)
 #endif
                    {
+itrace("notify_of_job_status: printing status of foreground job %d", job);
                      fprintf (stderr, "%s", j_strsignal (termsig));
 
                      if (WIFCORED (s))
index 6f038d4508a457d8a52f24ab65a51a61cd5af4c7..8c5d6fb65ad4284757dc1abf6663e6aadd3d7a1a 100644 (file)
@@ -818,7 +818,7 @@ rl_getc (FILE *stream)
       /* We know at this point that _rl_caught_signal == 0 */
 
 #if defined (__MINGW32__)
-      if (isatty (fd)
+      if (isatty (fd))
        return (_getch ());     /* "There is no error return." */
 #endif
       result = 0;
index 309857235fea8053cfdb0b31a26c154f8bd46b47..4d6cb3ba88433b84214a8f7812e960f378bc062e 100644 (file)
@@ -21,7 +21,6 @@ AC_CACHE_VAL(bash_cv_func_strtoimax,
   if test "$ac_cv_have_decl_strtoimax" = "yes" ; then
     HAVE_DECL_STRTOIMAX=1
   fi
-
   if test "$HAVE_STRTOIMAX" = 0 || test "$HAVE_DECL_STRTOIMAX" = 0 ; then
     bash_cv_func_strtoimax=no REPLACE_STRTOIMAX=1
   else
@@ -29,7 +28,10 @@ AC_CACHE_VAL(bash_cv_func_strtoimax,
   fi
 ])
 AC_MSG_RESULT($bash_cv_func_strtoimax)
-if test $bash_cv_func_strtoimax = yes; then
+if test "$ac_cv_have_decl_strtoimax" = "yes" ; then
+AC_DEFINE([HAVE_DECL_STRTOIMAX], [1])
+fi
+if test $bash_cv_func_strtoimax = no; then
 AC_LIBOBJ(strtoimax)
 fi
 ])
diff --git a/subst.c b/subst.c
index 89e40688f4838ff675011474c4d7ce507a3d8adb..bae6e3a11d52afcae73610d1103de7b70c471b5f 100644 (file)
--- a/subst.c
+++ b/subst.c
@@ -10862,7 +10862,7 @@ expand_array_subscript (string, sindex, quoted, flags)
   exp = substring (string, si+1, ni);
   t = expand_subscript_string (exp, quoted & ~(Q_ARITH|Q_DOUBLE_QUOTES));
   free (exp);
-  exp = sh_backslash_quote (t, abstab, 0);
+  exp = t ? sh_backslash_quote (t, abstab, 0) : savestring ("");
   free (t);
 
   slen = STRLEN (exp);
index 62278852a6348bd9bee4024a44ebcb071468df7b..36d4936363b4514915b72007f4248da11b6e0af6 100644 (file)
@@ -757,6 +757,8 @@ declare -A A=([$'\t']="X" ["*"]="X" [" "]="X" ["@"]="X" )
 declare -A A=(["*"]="X" ["@"]="X" )
 ./array27.sub: line 76: declare: `A[]]=X': not a valid identifier
 declare -A A=(["*"]="X" ["@"]="X" )
+./array27.sub: line 81: y[]: bad array subscript
+./array27.sub: line 81: y[]: bad array subscript
 declare -a bug4=([0]="" [1]="5" [2]="" [3]="1" [4]="")
 declare -a bug=([0]="" [1]="5" [2]="" [3]="1" [4]="")
 declare -a bug2=([0]="")
index e2a1e708360ae99754daaef25375a087afed1dbf..8564564140715c25a6427dedd0ed5dc2f339f24a 100644 (file)
@@ -76,3 +76,6 @@ for k in ']' '*' '@'; do
    declare "A[$k]=X"
 done
 declare -p A
+
+# empty arrays in arith contexts
+(( y[$none] ))