]> git.ipfire.org Git - thirdparty/bash.git/commitdiff
fix issue with failed history expansion changing the history list offset; fix some...
authorChet Ramey <chet.ramey@case.edu>
Mon, 30 Dec 2024 15:45:14 +0000 (10:45 -0500)
committerChet Ramey <chet.ramey@case.edu>
Mon, 30 Dec 2024 15:45:14 +0000 (10:45 -0500)
18 files changed:
CWRU/CWRU.chlog
MANIFEST
builtins/shopt.def
doc/bash.1
doc/bashref.texi
lib/readline/histexpand.c
lib/readline/util.c
sig.c
tests/comsub2.right
tests/cond-regexp2.sub
tests/cond.right
tests/exec.right
tests/extglob.right
tests/printf.right
tests/printf7.sub
tests/shopt.right
tests/varenv.right
trap.c

index bd87d2c9dce9715dbdd92c7095c65781a028d2e0..20d8bb3292aa5bd3513890202d0f6c16b7f64d69 100644 (file)
@@ -10772,3 +10772,21 @@ lib/readline/isearch.c
                                   -----
 CHANGES,NEWS
        - updated for bash-5.3-beta
+
+                                  12/15
+                                  -----
+lib/readline/histexpand.c
+       - get_history_event: make sure we don't change history_offset whether
+         the search succeeds or fails, don't set it to history_length.
+         Callers don't expect to have the history offset changed out from
+         under them.
+         Fixes bug reported by Grisha Levit <grishalevit@gmail.com>
+
+                                  12/16
+                                  -----
+lib/readline/util.c
+       - _rl_abort_internal: make sure to clear _rl_command_to_execute
+         Report and patch from Grisha Levit <grishalevit@gmail.com>
+
+tests/printf7.sub,tests/cond-regexp2.sub
+       - accommodate different error messages across different systems
index 2d43261e312c177b6b65b5c39f2a04b78c165dbe..48c7a6c4672c1cfdea92ecd3f3e42f5451f8c51f 100644 (file)
--- a/MANIFEST
+++ b/MANIFEST
@@ -645,6 +645,8 @@ po/ru.po            f
 po/sk.gmo              f
 po/sk.po               f
 po/sl.gmo              f
+po/sq.po               f
+po/sq.gmo              f
 po/sr.po               f
 po/sr.gmo              f
 po/sl.po               f
index 8d7ff4542568a996a7364642acf15d85c909a0a1..4994ebc46a57c5ad60e663574e910d98bca5bd9b 100644 (file)
@@ -70,7 +70,7 @@ $END
 #define UNSETOPT       0
 #define SETOPT         1
 
-#define OPTFMT         "%-15s\t%s\n"
+#define OPTFMT         "%-25s %s\n"
 
 extern int allow_null_glob_expansion, fail_glob_expansion, glob_dot_filenames;
 extern int cdable_vars, mail_warning, source_uses_path;
index a5a8e445c24acf299727f611cd03d3cf285cea01..171d8e309e712b353ec5e628e0fd42cd77977921 100644 (file)
@@ -1448,6 +1448,13 @@ array variables.
 Namerefs can be unset using the \fB\-n\fP option to the \fBunset\fP builtin.
 Otherwise, if \fBunset\fP is executed with the name of a nameref variable
 as an argument, the variable referenced by the nameref variable is unset.
+.PP
+When the shell starts, it reads its environment and creates a shell
+variable from each environment variable that has a valid name,
+as described below
+(see
+.SM
+.BR ENVIRONMENT ).
 .SS Positional Parameters
 A
 .I positional parameter
index dc7e36c006b4f2e3e0a0a745cc2d67e6b8f8be4f..43dd520d8696cb8d17ab0a3eaa1a3e49e42e090e 100644 (file)
@@ -1852,6 +1852,10 @@ Namerefs can be unset using the @option{-n} option to the @code{unset} builtin
 Otherwise, if @code{unset} is executed with the name of a nameref variable
 as an argument, the variable referenced by the nameref variable is unset.
 
+When the shell starts, it reads its environment and creates a shell
+variable from each environment variable that has a valid name,
+as described below (@pxref{Environment}).
+
 @node Positional Parameters
 @subsection Positional Parameters
 @cindex parameters, positional
index 068feccd1c29cb66b8bcef45445f949e534d92bd..fc0008e890c85e68a6dba97f067b55f21ab27db7 100644 (file)
@@ -141,7 +141,7 @@ get_history_event (const char *string, int *caller_index, int delimiting_quote)
   register char c;
   HIST_ENTRY *entry;
   int which, sign, local_index, substring_okay;
-  int search_flags;
+  int search_flags, old_offset;
   char *temp;
 
   /* The event can be specified in a number of ways.
@@ -251,9 +251,10 @@ get_history_event (const char *string, int *caller_index, int delimiting_quote)
 
   *caller_index = i;
 
+  old_offset = history_offset;         /* XXX */
 #define FAIL_SEARCH() \
   do { \
-    history_offset = history_length; xfree (temp) ; return (char *)NULL; \
+    history_offset = old_offset; xfree (temp) ; return (char *)NULL; \
   } while (0)
 
   /* If there is no search string, try to use the previous search string,
@@ -282,7 +283,7 @@ get_history_event (const char *string, int *caller_index, int delimiting_quote)
          entry = current_history ();
          if (entry == 0)
            FAIL_SEARCH ();
-         history_offset = history_length;
+         history_offset = old_offset;  /* XXX - was history_length */
        
          /* If this was a substring search, then remember the
             string that we matched for word substitution. */
index d03c899e57002afe4f4837cb73040bdee01aae89..0a5df9b4009e0a6a2832ab8f90767c45f0fc3910 100644 (file)
@@ -112,6 +112,7 @@ _rl_abort_internal (void)
   RL_UNSETSTATE (RL_STATE_MULTIKEY);   /* XXX */
 
   rl_last_func = (rl_command_func_t *)NULL;
+  _rl_command_to_execute = 0;
 
   _rl_longjmp (_rl_top_level, 1);
   return (0);
diff --git a/sig.c b/sig.c
index 54746815ea333b36a02110e92483d20b9fabfcf6..6de132597ce81c5f06615d253805d096a96cb6a8 100644 (file)
--- a/sig.c
+++ b/sig.c
@@ -574,8 +574,9 @@ termsig_sighandler (int sig)
   /* Set the event hook so readline will call it after the signal handlers
      finish executing, so if this interrupted character input we can get
      quick response.  If readline is active or has modified the terminal we
-     need to set this no matter what the signal is, though the check for
-     RL_STATE_TERMPREPPED is possibly redundant. */
+     need to set this no matter what the signal is; the check for
+     RL_STATE_TERMPREPPED is to handle the cases where we get a terminating
+     signal that readline *doesn't* handle while readline is executing. */
   if (RL_ISSTATE (RL_STATE_SIGHANDLER) || RL_ISSTATE (RL_STATE_TERMPREPPED))
     bashline_set_event_hook ();
   else if (RL_ISSTATE (RL_STATE_COMPLETING|RL_STATE_DISPATCHING))
index 1f9a3e2a30e68945e2992a56ee832757575cfbe1..29a333b099228bc27c3936b120550894d2653702 100644 (file)
@@ -23,27 +23,27 @@ JOBaa bb cc ddCONTROL
 NOTFOUND
 ./comsub2.tests: line 75: p: command not found
 ./comsub2.tests: line 75: p: command not found
-expand_aliases         off
-expand_aliases         off
+expand_aliases            off
+expand_aliases            off
 outside:
 ./comsub2.tests: line 79: alias: p: not found
 alias e='echo inside redefine'
-expand_aliases         off
+expand_aliases            off
 1
-expand_aliases         on
+expand_aliases            on
 2
-expand_aliases         on
+expand_aliases            on
 outside:
 ./comsub2.tests: line 89: alias: p: not found
-expand_aliases         on
+expand_aliases            on
 1
 xx
-expand_aliases         on
+expand_aliases            on
 2
 xx
-expand_aliases         on
+expand_aliases            on
 outside:
-expand_aliases         on
+expand_aliases            on
 inside: 12 22 42
 outside: 42 2
 newlines
index 0a0ade518aa1f36047670f9ef669dc1cf7411694..e4605a9f398f63d3ad4db3bcc07275501ff319d5 100644 (file)
 #   You should have received a copy of the GNU General Public License
 #   along with this program.  If not, see <http://www.gnu.org/licenses/>.
 #
+: ${TMPDIR:=/tmp}
+TMPF=$TMPDIR/cond-invalid-$RANDOM
+
+cond_invalid()
+{
+       local r;
+       rm -f "$TMPF"
+       line=$1 ; shift
+       lhs=$1 ; shift
+       rhs=$1 ; shift
+
+       [[ $lhs =~ $rhs ]] 2>"$TMPF"
+       r=$?
+       if [ ! -s "$TMPF" ]; then
+                echo "cond-regexp2.sub: $line: expected invalid regexp error output to stderr" >&2
+       fi
+       rm -f "$TMPF"
+       return $r;
+}
+
 [[ "\\" =~ ["."] ]] && echo bad 1
 
 [[ "\\" =~ "[.]" ]] && echo bad 2
 
-[[ "\\" =~ [\. ]] && echo bad 3
+cond_invalid $LINENO '\\' '[\.'  && echo bad 3
 
 [[ "\\" =~ [\.] ]] && echo bad 4
 
 [[ "\\" =~ [\\] ]] || echo bad 5
 
-[[ x =~ [z-a] ]] && echo bad 6
+cond_invalid $LINENO x '[z-a]' && echo bad 6
 
-[[ x =~ [[:invalid:]abc] ]] && echo bad 7
+cond_invalid $LINENO x '[[:invalid:]abc]' && echo bad 7
 
 exp='x\'
-[[ x =~ $exp ]] && echo bad 8
+cond_invalid $LINENO x "$exp" && echo bad 8
 
 exp='a(xb'
-[[ x =~ $exp ]] && echo bad 9
+cond_invalid $LINENO x "$exp"  && echo bad 9
 
 [[ dog =~ [[=d=]].. ]] && echo ok 1
 [[ d.. =~ [[=d=]]\.\. ]] && echo ok 2
index da3a2bb26ba085ecc5f642171ca07767f3e7bfbb..a658b6b3cbce565795bd6b43dc5b062ed913deeb 100644 (file)
@@ -84,11 +84,6 @@ match control-a 2
 match control-a 3
 match control-a 4
 match control-a 5
-./cond-regexp2.sub: line 18: [[: invalid regular expression `[\.': brackets ([ ]) not balanced
-./cond-regexp2.sub: line 24: [[: invalid regular expression `[z-a]': invalid character range
-./cond-regexp2.sub: line 26: [[: invalid regular expression `[[:invalid:]abc]': invalid character class
-./cond-regexp2.sub: line 29: [[: invalid regular expression `x\': trailing backslash (\)
-./cond-regexp2.sub: line 32: [[: invalid regular expression `a(xb': parentheses not balanced
 ok 1
 ok 2
 ok 3
index 0e908d9428707f7c7ef5d61511fda3aaf91c2461..ba5ae8904011fa60217b0e6bbb6cf187ea5cff54 100644 (file)
@@ -79,7 +79,7 @@ this is ohio-state
 1
 0
 testb
-expand_aliases         on
+expand_aliases            on
 1
 1
 1
index dca15ed53b4390ab35293423c2f8db3f3e98c113..59faee109dd55b9b751f93afd2347795ee79432b 100644 (file)
@@ -182,10 +182,10 @@ no dotglob: .a .foo bar
 ? . .. .a .foo
 *
 bar
-extglob                off
+extglob                   off
 x
-extglob                off
-extglob                off
-extglob                off
-extglob                off
-extglob                off
+extglob                   off
+extglob                   off
+extglob                   off
+extglob                   off
+extglob                   off
index 46d94edd93e20cf8cbf64e3ead953c337fce8c36..59d4413ab13d497a24fe83998c675199799febdc 100644 (file)
@@ -374,38 +374,21 @@ hello --
 0000000 340 262 207 040 040 040 055 055 055 012                        
 000000a
 [][]
-./printf7.sub: line 20: printf: 21474836470: Result too large
 []
-./printf7.sub: line 21: printf: 21474836470: Result too large
 [X]
-./printf7.sub: line 23: printf: 21474836470: Result too large
 VAR=[]
-./printf7.sub: line 26: printf: 21474836470: Result too large
 VAR=[X]
-./printf7.sub: line 32: printf: 9223372036854775825: Result too large
 []
-./printf7.sub: line 33: printf: 9223372036854775825: Result too large
 [X]
-./printf7.sub: line 35: printf: 9223372036854775825: Result too large
 VAR=[]
-./printf7.sub: line 38: printf: 9223372036854775825: Result too large
 VAR=[X]
-./printf7.sub: line 44: printf: 21474836470: Result too large
 []
-./printf7.sub: line 45: printf: 21474836470: Result too large
 [X]
-./printf7.sub: line 47: printf: 21474836470: Result too large
 VAR=[]
-./printf7.sub: line 50: printf: 21474836470: Result too large
 VAR=[X]
-./printf7.sub: line 56: printf: 9223372036854775825: Result too large
 []
-./printf7.sub: line 57: printf: 9223372036854775825: Result too large
 [X]
-./printf7.sub: line 59: printf: 9223372036854775825: Result too large
 VAR=[]
-./printf7.sub: line 62: printf: 9223372036854775825: Result too large
 VAR=[X]
 XY
-./printf7.sub: line 72: printf: 9223372036854775825: Result too large
 XY
index 8ca55171a554373ff60494496aa23dfa54831227..888e9d905c535d95317093015d22d021556440bb 100644 (file)
 #   along with this program.  If not, see <http://www.gnu.org/licenses/>.
 #
 
+: ${TMPDIR:=/tmp}
+TMPF=$TMPDIR/printf-oflow-$RANDOM
+
+printf_overflow ()
+{
+       local r;
+
+       line=$1 ; shift
+       rm -f "$TMPF"
+       printf "$@"  2>$TMPF
+       r=$?
+       if [ ! -s "$TMPF" ]; then
+               echo "printf7.sub: $line: expected overflow error output to stderr" >&2
+       fi
+       rm -f "$TMPF"
+       return $r
+}
+
 # tests of integer overflow for field width and precision arguments
 INT_MAX=$(getconf INT_MAX 2>/dev/null)
 [ -z "$INT_MAX" ] && INT_MAX=2147483647                # assume 32 bits
-TOOBIG=$(( $INT_MAX * 10 ))
+TOOBIG=${INT_MAX}0                             # effectively multiply by 10 
 
-printf '[%*s]\n' "${TOOBIG}"
-printf '[%*s]\n' "${TOOBIG}" X
+printf_overflow $LINENO '[%*s]\n' "${TOOBIG}"
+printf_overflow $LINENO '[%*s]\n' "${TOOBIG}" X
 
-printf -v VAR '[%*s]' "${TOOBIG}"
+printf_overflow $LINENO -v VAR '[%*s]' "${TOOBIG}"
 echo VAR="$VAR"
 unset -v VAR
-printf -v VAR '[%*s]' "${TOOBIG}" X
+printf_overflow $LINENO -v VAR '[%*s]' "${TOOBIG}" X
 echo VAR="$VAR"
 unset -v VAR
 
 TOOBIG=9223372036854775825
 
-printf '[%*s]\n' "${TOOBIG}"
-printf '[%*s]\n' "${TOOBIG}" X
+printf_overflow $LINENO '[%*s]\n' "${TOOBIG}"
+printf_overflow $LINENO '[%*s]\n' "${TOOBIG}" X
 
-printf -v VAR '[%*s]' "${TOOBIG}"
+printf_overflow $LINENO -v VAR '[%*s]' "${TOOBIG}"
 echo VAR="$VAR"
 unset -v VAR
-printf -v VAR '[%*s]' "${TOOBIG}" X
+printf_overflow $LINENO -v VAR '[%*s]' "${TOOBIG}" X
 echo VAR="$VAR"
 unset -v VAR
 
 TOOBIG=$(( $INT_MAX * 10 ))
 
-printf '[%.*s]\n' "${TOOBIG}"
-printf '[%.*s]\n' "${TOOBIG}" X
+printf_overflow $LINENO '[%.*s]\n' "${TOOBIG}"
+printf_overflow $LINENO '[%.*s]\n' "${TOOBIG}" X
 
-printf -v VAR '[%.*s]' "${TOOBIG}"
+printf_overflow $LINENO -v VAR '[%.*s]' "${TOOBIG}"
 echo VAR="$VAR"
 unset -v VAR
-printf -v VAR '[%.*s]' "${TOOBIG}" X
+printf_overflow $LINENO -v VAR '[%.*s]' "${TOOBIG}" X
 echo VAR="$VAR"
 unset -v VAR
 
 TOOBIG=9223372036854775825
 
-printf '[%.*s]\n' "${TOOBIG}"
-printf '[%.*s]\n' "${TOOBIG}" X
+printf_overflow $LINENO '[%.*s]\n' "${TOOBIG}"
+printf_overflow $LINENO '[%.*s]\n' "${TOOBIG}" X
 
-printf -v VAR '[%.*s]' "${TOOBIG}"
+printf_overflow $LINENO -v VAR '[%.*s]' "${TOOBIG}"
 echo VAR="$VAR"
 unset -v VAR
-printf -v VAR '[%.*s]' "${TOOBIG}" X
+printf_overflow $LINENO -v VAR '[%.*s]' "${TOOBIG}" X
 echo VAR="$VAR"
 unset -v VAR
 
@@ -69,4 +87,5 @@ unset -v VAR
 #printf "%.${TOOBIG}s\n" XY
 printf -v VAR "%.${TOOBIG}s\n" XY
 echo $VAR
-printf "%.${TOOBIG}Q\n" XY
+unset -v VAR
+printf_overflow $LINENO "%.${TOOBIG}Q\n" XY
index 80a42814f25d564982b79ec30777d812a8a5ec86..bbbc439ce04171524aeaf0ab921b4e822395d05a 100644 (file)
@@ -126,51 +126,51 @@ shopt -u shift_verbose
 shopt -u varredir_close
 shopt -u xpg_echo
 --
-array_expand_once      off
-assoc_expand_once      off
-autocd                 off
-bash_source_fullpath   off
-cdable_vars            off
-checkhash              off
-checkjobs              off
-checkwinsize           off
-compat31               off
-compat32               off
-compat40               off
-compat41               off
-compat42               off
-compat43               off
-compat44               off
-direxpand              off
-dirspell               off
-dotglob                off
-execfail               off
-extdebug               off
-extglob                off
-failglob               off
-globstar               off
-gnu_errfmt             off
-histappend             off
-histreedit             off
-histverify             off
-huponexit              off
-inherit_errexit        off
-lastpipe               off
-lithist                off
-localvar_inherit       off
-localvar_unset         off
-login_shell            off
-mailwarn               off
-no_empty_cmd_completion        off
-nocaseglob             off
-nocasematch            off
-noexpand_translation   off
-nullglob               off
-progcomp_alias         off
-restricted_shell       off
-shift_verbose          off
-varredir_close         off
-xpg_echo               off
+array_expand_once         off
+assoc_expand_once         off
+autocd                    off
+bash_source_fullpath      off
+cdable_vars               off
+checkhash                 off
+checkjobs                 off
+checkwinsize              off
+compat31                  off
+compat32                  off
+compat40                  off
+compat41                  off
+compat42                  off
+compat43                  off
+compat44                  off
+direxpand                 off
+dirspell                  off
+dotglob                   off
+execfail                  off
+extdebug                  off
+extglob                   off
+failglob                  off
+globstar                  off
+gnu_errfmt                off
+histappend                off
+histreedit                off
+histverify                off
+huponexit                 off
+inherit_errexit           off
+lastpipe                  off
+lithist                   off
+localvar_inherit          off
+localvar_unset            off
+login_shell               off
+mailwarn                  off
+no_empty_cmd_completion   off
+nocaseglob                off
+nocasematch               off
+noexpand_translation      off
+nullglob                  off
+progcomp_alias            off
+restricted_shell          off
+shift_verbose             off
+varredir_close            off
+xpg_echo                  off
 --
 set +o allexport
 set -o braceexpand
@@ -310,5 +310,5 @@ xtrace              off
 --
 ./shopt.tests: line 106: shopt: xyz1: invalid shell option name
 ./shopt.tests: line 107: shopt: xyz1: invalid option name
-expand_aliases         on
-expand_aliases         on
+expand_aliases            on
+expand_aliases            on
index 1566626a5718f3f2ffbb877f8f930085d4c9cf4e..e01896811d04b5def5b8401b6435a7e2910818c2 100644 (file)
@@ -270,9 +270,9 @@ declare -x v="x"
 declare -x v="t"
 declare -- v
 declare -x v
-ignoreeof              on
-ignoreeof              off
-ignoreeof              on
+ignoreeof                 on
+ignoreeof                 off
+ignoreeof                 on
 10
 local -
 match 1
diff --git a/trap.c b/trap.c
index 33fa04d0610cf9655b776c630aad780e50709ec7..1b3365f409d8e325cb9d9f95146ce65d4e2d5b80 100644 (file)
--- a/trap.c
+++ b/trap.c
@@ -613,7 +613,11 @@ trap_handler (int sig)
       /* Set the event hook so readline will call it after the signal handlers
         finish executing, so if this interrupted character input we can get
         quick response. */
+#if 1
       if (RL_ISSTATE (RL_STATE_SIGHANDLER))
+#else
+      if (RL_ISSTATE (RL_STATE_SIGHANDLER) || RL_ISSTATE (RL_STATE_TERMPREPPED))
+#endif
         bashline_set_event_hook ();
 #endif