From: Chet Ramey Date: Mon, 30 Dec 2024 15:45:14 +0000 (-0500) Subject: fix issue with failed history expansion changing the history list offset; fix some... X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=5114e17172276cf5a2f889f8037ae58c4cb05bb9;p=thirdparty%2Fbash.git fix issue with failed history expansion changing the history list offset; fix some tests to avoid problems with error messages that differ between systems; fix issue with readline rl_abort not clearing any pending command to execute --- diff --git a/CWRU/CWRU.chlog b/CWRU/CWRU.chlog index bd87d2c9..20d8bb32 100644 --- a/CWRU/CWRU.chlog +++ b/CWRU/CWRU.chlog @@ -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 + + 12/16 + ----- +lib/readline/util.c + - _rl_abort_internal: make sure to clear _rl_command_to_execute + Report and patch from Grisha Levit + +tests/printf7.sub,tests/cond-regexp2.sub + - accommodate different error messages across different systems diff --git a/MANIFEST b/MANIFEST index 2d43261e..48c7a6c4 100644 --- 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 diff --git a/builtins/shopt.def b/builtins/shopt.def index 8d7ff454..4994ebc4 100644 --- a/builtins/shopt.def +++ b/builtins/shopt.def @@ -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; diff --git a/doc/bash.1 b/doc/bash.1 index a5a8e445..171d8e30 100644 --- a/doc/bash.1 +++ b/doc/bash.1 @@ -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 diff --git a/doc/bashref.texi b/doc/bashref.texi index dc7e36c0..43dd520d 100644 --- a/doc/bashref.texi +++ b/doc/bashref.texi @@ -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 diff --git a/lib/readline/histexpand.c b/lib/readline/histexpand.c index 068feccd..fc0008e8 100644 --- a/lib/readline/histexpand.c +++ b/lib/readline/histexpand.c @@ -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. */ diff --git a/lib/readline/util.c b/lib/readline/util.c index d03c899e..0a5df9b4 100644 --- a/lib/readline/util.c +++ b/lib/readline/util.c @@ -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 54746815..6de13259 100644 --- 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)) diff --git a/tests/comsub2.right b/tests/comsub2.right index 1f9a3e2a..29a333b0 100644 --- a/tests/comsub2.right +++ b/tests/comsub2.right @@ -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 diff --git a/tests/cond-regexp2.sub b/tests/cond-regexp2.sub index 0a0ade51..e4605a9f 100644 --- a/tests/cond-regexp2.sub +++ b/tests/cond-regexp2.sub @@ -11,25 +11,45 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . # +: ${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 diff --git a/tests/cond.right b/tests/cond.right index da3a2bb2..a658b6b3 100644 --- a/tests/cond.right +++ b/tests/cond.right @@ -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 diff --git a/tests/exec.right b/tests/exec.right index 0e908d94..ba5ae890 100644 --- a/tests/exec.right +++ b/tests/exec.right @@ -79,7 +79,7 @@ this is ohio-state 1 0 testb -expand_aliases on +expand_aliases on 1 1 1 diff --git a/tests/extglob.right b/tests/extglob.right index dca15ed5..59faee10 100644 --- a/tests/extglob.right +++ b/tests/extglob.right @@ -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 diff --git a/tests/printf.right b/tests/printf.right index 46d94edd..59d4413a 100644 --- a/tests/printf.right +++ b/tests/printf.right @@ -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 diff --git a/tests/printf7.sub b/tests/printf7.sub index 8ca55171..888e9d90 100644 --- a/tests/printf7.sub +++ b/tests/printf7.sub @@ -12,54 +12,72 @@ # along with this program. If not, see . # +: ${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 diff --git a/tests/shopt.right b/tests/shopt.right index 80a42814..bbbc439c 100644 --- a/tests/shopt.right +++ b/tests/shopt.right @@ -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 diff --git a/tests/varenv.right b/tests/varenv.right index 1566626a..e0189681 100644 --- a/tests/varenv.right +++ b/tests/varenv.right @@ -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 33fa04d0..1b3365f4 100644 --- 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