From: Chet Ramey Date: Fri, 9 Feb 2024 15:30:02 +0000 (-0500) Subject: fix nofork comsub overwriting currently executing command; free readline undo list... X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=dc97ded4344b968f78b44647225629e0a19e6909;p=thirdparty%2Fbash.git fix nofork comsub overwriting currently executing command; free readline undo list on signal in callback mode; avoid disabling readonly when assigning variables from the environment; fix bug with shell-expand-line and $'...' quoting inside command substitutions; add `bash-vi-complete' as bindable command name --- diff --git a/CWRU/CWRU.chlog b/CWRU/CWRU.chlog index 8c5dc98ad..058e667db 100644 --- a/CWRU/CWRU.chlog +++ b/CWRU/CWRU.chlog @@ -8503,3 +8503,55 @@ builtins/printf.def - PRETURN: clean up vbuf only if vflag is set, and clean it up on error (it would get cleaned up on the next call, but...) Fixes from Grisha Levit + + 2/2 + --- +doc/bash.1,doc/bashref.texi + - word expansions: make it clearer that quote removal is one of the + shell word expansions + +execute_cmd.c,execute_cmd.h + - currently_executing_command: no longer static, so other parts of + the shell can save and restore it if necessary + +subst.c + - function_substitute: unwind-protect currently_executing_command, + since parse_and_execute can overwrite it in the current shell + execution context. + Report from Grisha Levit + +lib/readline/readline.c + - readline_common_teardown: new function from the guts of + readline_internal_teardown, manages and deallocates rl_undo_list. + +lib/readline/callback.c + - rl_callback_handler_remove: if we're removing the line handler + while we still have an undo list, we didn't call + readline_internal_teardown. Call readline_common_teardown to manage + the undo list in case we are calling this from a signal handler + but not exiting the program. + Fixes leaks reported by sparrowhawk996@gmail.com. + +variables.c + - initialize_shell_variables: use ASS_FORCE when binding SHELLOPTS or + BASHOPTS if we get them from the environment, in case they've + already been created as shell variables and set to readonly (like + changes from 1/30) + - set_ppid: use ASS_FORCE in the call to bind_variable instead of + temporarily turning off att_readonly + +subst.c + - extract_delimited_string: pass FLAGS down to skip_single_quoted and + skip_double_quoted so we propagate SX_COMMAND and SX_COMPLETE + properly. + Fixes bug reported by A4-Tacks + + 2/3 + --- +bashline.c + - initialize_readline: add `bash-vi-complete' as a bindable command + name so users can bind other key sequences to it + - vi_advance_point: function to advance point by one character even + in the presence of multibyte characters + - bash_vi_complete: call vi_advance_point instead of just incrementing + rl_point diff --git a/Makefile.in b/Makefile.in index b52069e1f..2f863e869 100644 --- a/Makefile.in +++ b/Makefile.in @@ -1,6 +1,6 @@ # Makefile for bash-5.2, version 5.1 # -# Copyright (C) 1996-2021 Free Software Foundation, Inc. +# Copyright (C) 1996-2024 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/arrayfunc.c b/arrayfunc.c index 57ab0fc37..d56be4283 100644 --- a/arrayfunc.c +++ b/arrayfunc.c @@ -1,6 +1,6 @@ /* arrayfunc.c -- High-level array functions used by other parts of the shell. */ -/* Copyright (C) 2001-2023 Free Software Foundation, Inc. +/* Copyright (C) 2001-2024 Free Software Foundation, Inc. This file is part of GNU Bash, the Bourne Again SHell. diff --git a/bashline.c b/bashline.c index c11484ecf..c09152c52 100644 --- a/bashline.c +++ b/bashline.c @@ -1,6 +1,6 @@ /* bashline.c -- Bash's interface to the readline library. */ -/* Copyright (C) 1987-2023 Free Software Foundation, Inc. +/* Copyright (C) 1987-2024 Free Software Foundation, Inc. This file is part of GNU Bash, the Bourne Again SHell. @@ -606,6 +606,7 @@ initialize_readline (void) rl_bind_key_if_unbound_in_map ('@', posix_edit_macros, vi_movement_keymap); # endif + rl_add_defun ("bash-vi-complete", bash_vi_complete, -1); rl_bind_key_in_map ('\\', bash_vi_complete, vi_movement_keymap); rl_bind_key_in_map ('*', bash_vi_complete, vi_movement_keymap); rl_bind_key_in_map ('=', bash_vi_complete, vi_movement_keymap); @@ -4012,10 +4013,38 @@ bash_specific_completion (int what_to_do, rl_compentry_func_t *generator) #endif /* SPECIFIC_COMPLETION_FUNCTIONS */ #if defined (VI_MODE) +/* This does pretty much what _rl_vi_advance_point does. */ +static inline int +vi_advance_point (void) +{ + int point; + DECLARE_MBSTATE; + + point = rl_point; + if (rl_point < rl_end) +#if defined (HANDLE_MULTIBYTE) + { + if (locale_mb_cur_max == 1) + rl_point++; + else + { + point = rl_point; + ADVANCE_CHAR (rl_line_buffer, rl_end, rl_point); + if (point == rl_point || rl_point > rl_end) + rl_point = rl_end; + } + } +#else + rl_point++: +#endif + return point; +} + /* Completion, from vi mode's point of view. This is a modified version of rl_vi_complete which uses the bash globbing code to implement what POSIX - specifies, which is to append a `*' and attempt filename generation (which - has the side effect of expanding any globbing characters in the word). */ + specifies, which is to optinally append a `*' and attempt filename + generation (which has the side effect of expanding any globbing characters + in the word). */ static int bash_vi_complete (int count, int key) { @@ -4027,7 +4056,7 @@ bash_vi_complete (int count, int key) { if (!whitespace (rl_line_buffer[rl_point + 1])) rl_vi_end_word (1, 'E'); - rl_point++; + vi_advance_point (); } /* Find boundaries of current word, according to vi definition of a diff --git a/braces.c b/braces.c index e2517c981..17d280734 100644 --- a/braces.c +++ b/braces.c @@ -1,7 +1,7 @@ /* braces.c -- code for doing word expansion in curly braces. */ -/* Copyright (C) 1987-2020,2022-2023 Free Software Foundation, Inc. - +/* Copyright (C) 1987-2020,2022-2024 Free Software Foundation, Inc. +` This file is part of GNU Bash, the Bourne Again SHell. Bash is free software: you can redistribute it and/or modify diff --git a/builtins/cd.def b/builtins/cd.def index c8676749e..c99d67cfc 100644 --- a/builtins/cd.def +++ b/builtins/cd.def @@ -1,7 +1,7 @@ This file is cd.def, from which is created cd.c. It implements the builtins "cd" and "pwd" in Bash. -Copyright (C) 1987-2023 Free Software Foundation, Inc. +Copyright (C) 1987-2024 Free Software Foundation, Inc. This file is part of GNU Bash, the Bourne Again SHell. diff --git a/builtins/hash.def b/builtins/hash.def index dd0bf76f4..ee8da9d00 100644 --- a/builtins/hash.def +++ b/builtins/hash.def @@ -1,7 +1,7 @@ This file is hash.def, from which is created hash.c. It implements the builtin "hash" in Bash. -Copyright (C) 1987-2023 Free Software Foundation, Inc. +Copyright (C) 1987-2024 Free Software Foundation, Inc. This file is part of GNU Bash, the Bourne Again SHell. diff --git a/builtins/printf.def b/builtins/printf.def index 80d536b44..f7f4de34a 100644 --- a/builtins/printf.def +++ b/builtins/printf.def @@ -175,7 +175,7 @@ extern int errno; nw = vflag ? vbprintf (f, precision, func) : printf (f, precision, func); \ else \ nw = vflag ? vbprintf (f, func) : printf (f, func); \ - if (nw < 0 || ferror (stdout)) \ + if (nw < 0 || (vflag == 0 && ferror (stdout))) \ { \ QUIT; \ if (vflag) \ diff --git a/builtins/set.def b/builtins/set.def index e0024a973..13630c22d 100644 --- a/builtins/set.def +++ b/builtins/set.def @@ -1,7 +1,7 @@ This file is set.def, from which is created set.c. It implements the "set" and "unset" builtins in Bash. -Copyright (C) 1987-2023 Free Software Foundation, Inc. +Copyright (C) 1987-2024 Free Software Foundation, Inc. This file is part of GNU Bash, the Bourne Again SHell. diff --git a/builtins/shopt.def b/builtins/shopt.def index e6c77cc5a..b3e1cfe50 100644 --- a/builtins/shopt.def +++ b/builtins/shopt.def @@ -1,7 +1,7 @@ This file is shopt.def, from which is created shopt.c. It implements the Bash `shopt' builtin. -Copyright (C) 1994-2023 Free Software Foundation, Inc. +Copyright (C) 1994-2024 Free Software Foundation, Inc. This file is part of GNU Bash, the Bourne Again SHell. diff --git a/builtins/ulimit.def b/builtins/ulimit.def index 64c31e148..1c3ad1fa3 100644 --- a/builtins/ulimit.def +++ b/builtins/ulimit.def @@ -1,7 +1,7 @@ This file is ulimit.def, from which is created ulimit.c. It implements the builtin "ulimit" in Bash. -Copyright (C) 1987-2023 Free Software Foundation, Inc. +Copyright (C) 1987-2024 Free Software Foundation, Inc. This file is part of GNU Bash, the Bourne Again SHell. diff --git a/builtins/wait.def b/builtins/wait.def index 3f8461978..a0e43bf82 100644 --- a/builtins/wait.def +++ b/builtins/wait.def @@ -1,7 +1,7 @@ This file is wait.def, from which is created wait.c. It implements the builtin "wait" in Bash. -Copyright (C) 1987-2023 Free Software Foundation, Inc. +Copyright (C) 1987-2024 Free Software Foundation, Inc. This file is part of GNU Bash, the Bourne Again SHell. diff --git a/doc/bash.1 b/doc/bash.1 index bd916b28b..ff51f89bc 100644 --- a/doc/bash.1 +++ b/doc/bash.1 @@ -5,14 +5,14 @@ .\" Case Western Reserve University .\" chet.ramey@case.edu .\" -.\" Last Change: Thu Jan 18 11:41:18 EST 2024 +.\" Last Change: Fri Feb 2 09:38:21 EST 2024 .\" .\" bash_builtins, strip all but Built-Ins section .\" avoid a warning about an undefined register .\" .if !rzY .nr zY 0 .if \n(zZ=1 .ig zZ .if \n(zY=1 .ig zY -.TH BASH 1 "2024 January 18" "GNU Bash 5.3" +.TH BASH 1 "2024 February 2" "GNU Bash 5.3" .\" .\" There's some problem with having a `@' .\" in a tagged paragraph with the BSD man macros. @@ -2978,22 +2978,24 @@ builtins display array values in a way that allows them to be reused as assignments. .SH EXPANSION Expansion is performed on the command line after it has been split into -words. There are seven kinds of expansion performed: +words. The shell performs these expansions: .IR "brace expansion" , .IR "tilde expansion" , .IR "parameter and variable expansion" , .IR "command substitution" , .IR "arithmetic expansion" , .IR "word splitting" , +.IR "pathname expansion" , and -.IR "pathname expansion" . +.IR "quote removal . .PP The order of expansions is: brace expansion; tilde expansion, parameter and variable expansion, arithmetic expansion, and command substitution (done in a left-to-right fashion); word splitting; -and pathname expansion. +pathname expansion; +and quote removal. .PP On systems that can support it, there is an additional expansion available: \fIprocess substitution\fP. @@ -3001,9 +3003,10 @@ This is performed at the same time as tilde, parameter, variable, and arithmetic expansion and command substitution. .PP -After these expansions are performed, quote characters present in the -original word are removed unless they have been quoted themselves -(\fIquote removal\fP). +\fIQuote removal\fP is always performed last. +It removes quote characters present in the original word, +not ones resulting from one of the other expansions, +unless they have been quoted themselves. .PP Only brace expansion, word splitting, and pathname expansion can increase the number of words of the expansion; other expansions @@ -6825,7 +6828,9 @@ Expand the line by performing shell word expansions. This performs alias and history expansion, \fB$\fP\(aq\fIstring\fP\(aq and \fB$\fP\(dq\fIstring\fP\(dq quoting, tilde expansion, parameter and variable expansion, arithmetic expansion, +command and process substitution, word splitting, and quote removal. +An explicit argument suppresses command and process substitution. See .SM .B HISTORY EXPANSION diff --git a/doc/bashref.texi b/doc/bashref.texi index 41bdcd5ae..e50494eb2 100644 --- a/doc/bashref.texi +++ b/doc/bashref.texi @@ -1911,7 +1911,8 @@ to the filename used to invoke Bash, as given by argument zero. @cindex expansion Expansion is performed on the command line after it has been split into -@code{token}s. There are seven kinds of expansion performed: +@code{token}s. +Bash performs these expansions: @itemize @bullet @item brace expansion @@ -1921,6 +1922,7 @@ Expansion is performed on the command line after it has been split into @item arithmetic expansion @item word splitting @item filename expansion +@item quote removal @end itemize @menu @@ -1943,7 +1945,8 @@ brace expansion; tilde expansion, parameter and variable expansion, arithmetic expansion, and command substitution (done in a left-to-right fashion); word splitting; -and filename expansion. +filename expansion; +and quote removal. On systems that can support it, there is an additional expansion available: @dfn{process substitution}. @@ -1951,9 +1954,11 @@ This is performed at the same time as tilde, parameter, variable, and arithmetic expansion and command substitution. -After these expansions are performed, quote characters present in the -original word are removed unless they have been quoted themselves -(@dfn{quote removal}). @xref{Quote Removal} for more details. +@dfn{Quote removal} is always performed last. +It removes quote characters present in the original word, +not ones resulting from one of the other expansions, +unless they have been quoted themselves. +@xref{Quote Removal} for more details. Only brace expansion, word splitting, and filename expansion can increase the number of words of the expansion; other expansions @@ -3900,7 +3905,7 @@ If @var{directory} is not supplied, the value of the @env{HOME} shell variable is used. If the shell variable @env{CDPATH} exists, @code{cd} uses it as a search path: -{cd} searches each directory name in @env{CDPATH} for +@code{cd} searches each directory name in @env{CDPATH} for @var{directory}, with alternative directory names in @env{CDPATH} separated by a colon (@samp{:}). If @var{directory} begins with a slash, @env{CDPATH} is not used. diff --git a/doc/version.texi b/doc/version.texi index bc3d5d1d4..4e6a512ec 100644 --- a/doc/version.texi +++ b/doc/version.texi @@ -2,10 +2,10 @@ Copyright (C) 1988-2024 Free Software Foundation, Inc. @end ignore -@set LASTCHANGE Mon Jan 15 13:13:50 EST 2024 +@set LASTCHANGE Fri Feb 2 09:37:55 EST 2024 @set EDITION 5.3 @set VERSION 5.3 -@set UPDATED 15 January 2024 -@set UPDATED-MONTH January 2024 +@set UPDATED 2 February 2024 +@set UPDATED-MONTH February 2024 diff --git a/execute_cmd.c b/execute_cmd.c index f13114b93..0a5e33051 100644 --- a/execute_cmd.c +++ b/execute_cmd.c @@ -1,6 +1,6 @@ /* execute_cmd.c -- Execute a COMMAND structure. */ -/* Copyright (C) 1987-2023 Free Software Foundation, Inc. +/* Copyright (C) 1987-2024 Free Software Foundation, Inc. This file is part of GNU Bash, the Bourne Again SHell. @@ -207,6 +207,9 @@ char *this_command_name; a debugger to know where exactly the program is currently executing. */ char *the_printed_command_except_trap; +/* Used to compute the correct line number. */ +COMMAND *currently_executing_command; + /* For catching RETURN in a function. */ int return_catch_flag; int return_catch_value; @@ -267,8 +270,6 @@ struct stat SB; /* used for debugging */ static int special_builtin_failed; -static COMMAND *currently_executing_command; - /* The line number that the currently executing function starts on. */ static int function_line_number; diff --git a/execute_cmd.h b/execute_cmd.h index 44c60ba8a..f55409999 100644 --- a/execute_cmd.h +++ b/execute_cmd.h @@ -63,6 +63,7 @@ extern int stdin_redir; extern int line_number_for_err_trap; extern char *the_printed_command_except_trap; +extern COMMAND *currently_executing_command; extern char *this_command_name; extern SHELL_VAR *this_shell_function; diff --git a/externs.h b/externs.h index 6bd136641..6376bf41e 100644 --- a/externs.h +++ b/externs.h @@ -1,7 +1,7 @@ /* externs.h -- extern function declarations which do not appear in their own header file. */ -/* Copyright (C) 1993-2023 Free Software Foundation, Inc. +/* Copyright (C) 1993-2024 Free Software Foundation, Inc. This file is part of GNU Bash, the Bourne Again SHell. diff --git a/general.c b/general.c index 636009997..94082fdf8 100644 --- a/general.c +++ b/general.c @@ -1,6 +1,6 @@ /* general.c -- Stuff that is used by all files. */ -/* Copyright (C) 1987-2023 Free Software Foundation, Inc. +/* Copyright (C) 1987-2024 Free Software Foundation, Inc. This file is part of GNU Bash, the Bourne Again SHell. diff --git a/jobs.c b/jobs.c index f9fc82376..c0569c2e1 100644 --- a/jobs.c +++ b/jobs.c @@ -3,7 +3,7 @@ /* This file works with both POSIX and BSD systems. It implements job control. */ -/* Copyright (C) 1989-2023 Free Software Foundation, Inc. +/* Copyright (C) 1989-2024 Free Software Foundation, Inc. This file is part of GNU Bash, the Bourne Again SHell. diff --git a/jobs.h b/jobs.h index ff6677a09..7ac7b22bd 100644 --- a/jobs.h +++ b/jobs.h @@ -1,6 +1,6 @@ /* jobs.h -- structures and definitions used by the jobs.c file. */ -/* Copyright (C) 1993-2023 Free Software Foundation, Inc. +/* Copyright (C) 1993-2024 Free Software Foundation, Inc. This file is part of GNU Bash, the Bourne Again SHell. diff --git a/lib/readline/callback.c b/lib/readline/callback.c index d376f948f..180b683f9 100644 --- a/lib/readline/callback.c +++ b/lib/readline/callback.c @@ -1,6 +1,6 @@ /* callback.c -- functions to use readline as an X `callback' mechanism. */ -/* Copyright (C) 1987-2022 Free Software Foundation, Inc. +/* Copyright (C) 1987-2024 Free Software Foundation, Inc. This file is part of the GNU Readline Library (Readline), a library for reading lines of text with interactive input and history editing. @@ -323,6 +323,15 @@ rl_callback_handler_remove (void) rl_linefunc = NULL; RL_UNSETSTATE (RL_STATE_CALLBACK); RL_CHECK_SIGNALS (); + + /* Do what we need to do to manage the undo list if we haven't already done + it in rl_callback_read_char(). If there's no undo list, we don't need to + do anything. It doesn't matter if we try to revert all previous lines a + second time; none of the history entries will have an undo list. */ + if (rl_undo_list) + readline_common_teardown (); + /* At this point, rl_undo_list == NULL. */ + if (in_handler) { in_handler = 0; diff --git a/lib/readline/complete.c b/lib/readline/complete.c index d0165cc73..f564a47f5 100644 --- a/lib/readline/complete.c +++ b/lib/readline/complete.c @@ -1,6 +1,6 @@ /* complete.c -- filename completion for readline. */ -/* Copyright (C) 1987-2022,2023 Free Software Foundation, Inc. +/* Copyright (C) 1987-2024 Free Software Foundation, Inc. This file is part of the GNU Readline Library (Readline), a library for reading lines of text with interactive input and history editing. diff --git a/lib/readline/doc/rluser.texi b/lib/readline/doc/rluser.texi index aa64852e9..1e3823cf2 100644 --- a/lib/readline/doc/rluser.texi +++ b/lib/readline/doc/rluser.texi @@ -1,5 +1,7 @@ @comment %**start of header (This is for running Texinfo on a region.) +@ifclear BashFeatures @setfilename rluser.info +@end ifclear @comment %**end of header (This is for running Texinfo on a region.) @ignore @@ -1874,8 +1876,10 @@ Display version information about the current instance of Bash. Expand the line by performing shell word expansions. This performs alias and history expansion, $'@var{string}' and $"@var{string}" quoting, -tilde expansion, parameter and variable expansion, arithmetic expansion, +tilde expansion, parameter and variable expansion, arithmetic expansion, +command and proces substitution, word splitting, and quote removal. +An explicit argument suppresses command and process substitution. @item history-expand-line (M-^) Perform history expansion on the current line. diff --git a/lib/readline/misc.c b/lib/readline/misc.c index bbb0332a5..96c82b54d 100644 --- a/lib/readline/misc.c +++ b/lib/readline/misc.c @@ -1,6 +1,6 @@ /* misc.c -- miscellaneous bindable readline functions. */ -/* Copyright (C) 1987-2023 Free Software Foundation, Inc. +/* Copyright (C) 1987-2024 Free Software Foundation, Inc. This file is part of the GNU Readline Library (Readline), a library for reading lines of text with interactive input and history editing. diff --git a/lib/readline/readline.c b/lib/readline/readline.c index 696eee800..979090979 100644 --- a/lib/readline/readline.c +++ b/lib/readline/readline.c @@ -474,17 +474,12 @@ readline_internal_setup (void) RL_CHECK_SIGNALS (); } -STATIC_CALLBACK char * -readline_internal_teardown (int eof) +STATIC_CALLBACK void +readline_common_teardown (void) { char *temp; HIST_ENTRY *entry; - RL_CHECK_SIGNALS (); - - if (eof) - RL_SETSTATE (RL_STATE_EOF); /* XXX */ - /* Restore the original of this history line, iff the line that we are editing was originally in the history, AND the line has changed. */ entry = current_history (); @@ -510,6 +505,17 @@ readline_internal_teardown (int eof) rid of it now. */ if (rl_undo_list) rl_free_undo_list (); +} + +STATIC_CALLBACK char * +readline_internal_teardown (int eof) +{ + RL_CHECK_SIGNALS (); + + if (eof) + RL_SETSTATE (RL_STATE_EOF); /* XXX */ + + readline_common_teardown (); /* Disable the meta key, if this terminal has one and we were told to use it. The check whether or not we sent the enable string is in diff --git a/lib/readline/readline.h b/lib/readline/readline.h index 3224706f7..22b9ca9b6 100644 --- a/lib/readline/readline.h +++ b/lib/readline/readline.h @@ -1,6 +1,6 @@ /* Readline.h -- the names of functions callable from within readline. */ -/* Copyright (C) 1987-2023 Free Software Foundation, Inc. +/* Copyright (C) 1987-2024 Free Software Foundation, Inc. This file is part of the GNU Readline Library (Readline), a library for reading lines of text with interactive input and history editing. diff --git a/lib/readline/rlprivate.h b/lib/readline/rlprivate.h index a2ab98bc1..61d04a459 100644 --- a/lib/readline/rlprivate.h +++ b/lib/readline/rlprivate.h @@ -1,7 +1,7 @@ /* rlprivate.h -- functions and variables global to the readline library, but not intended for use by applications. */ -/* Copyright (C) 1999-2023 Free Software Foundation, Inc. +/* Copyright (C) 1999-2024 Free Software Foundation, Inc. This file is part of the GNU Readline Library (Readline), a library for reading lines of text with interactive input and history editing. @@ -270,10 +270,11 @@ extern char *_rl_savestring (const char *); * Undocumented private functions * *************************************************************************/ -#if defined(READLINE_CALLBACKS) +#if defined (READLINE_CALLBACKS) /* readline.c */ extern void readline_internal_setup (void); +extern void readline_common_teardown (void); extern char *readline_internal_teardown (int); extern int readline_internal_char (void); diff --git a/lib/readline/search.c b/lib/readline/search.c index 6b078d7c2..a22c43d4f 100644 --- a/lib/readline/search.c +++ b/lib/readline/search.c @@ -1,6 +1,6 @@ /* search.c - code for non-incremental searching in emacs and vi modes. */ -/* Copyright (C) 1992-2023 Free Software Foundation, Inc. +/* Copyright (C) 1992-2024 Free Software Foundation, Inc. This file is part of the GNU Readline Library (Readline), a library for reading lines of text with interactive input and history editing. diff --git a/lib/readline/signals.c b/lib/readline/signals.c index 92dd2ffc9..706035e9f 100644 --- a/lib/readline/signals.c +++ b/lib/readline/signals.c @@ -1,6 +1,6 @@ /* signals.c -- signal handling support for readline. */ -/* Copyright (C) 1987-2021 Free Software Foundation, Inc. +/* Copyright (C) 1987-2024 Free Software Foundation, Inc. This file is part of the GNU Readline Library (Readline), a library for reading lines of text with interactive input and history editing. diff --git a/lib/readline/text.c b/lib/readline/text.c index 26ded8f3b..c5281efe1 100644 --- a/lib/readline/text.c +++ b/lib/readline/text.c @@ -1,6 +1,6 @@ /* text.c -- text handling commands for readline. */ -/* Copyright (C) 1987-2021,2023 Free Software Foundation, Inc. +/* Copyright (C) 1987-2021,2023-2024 Free Software Foundation, Inc. This file is part of the GNU Readline Library (Readline), a library for reading lines of text with interactive input and history editing. diff --git a/lib/sh/eaccess.c b/lib/sh/eaccess.c index abeead2d6..0d2c44b5c 100644 --- a/lib/sh/eaccess.c +++ b/lib/sh/eaccess.c @@ -1,6 +1,6 @@ /* eaccess.c - eaccess replacement for the shell, plus other access functions. */ -/* Copyright (C) 2006-2020,2022-2023 Free Software Foundation, Inc. +/* Copyright (C) 2006-2020,2022-2024 Free Software Foundation, Inc. This file is part of GNU Bash, the Bourne Again SHell. diff --git a/lib/sh/tmpfile.c b/lib/sh/tmpfile.c index 650c0ac0e..006b6b177 100644 --- a/lib/sh/tmpfile.c +++ b/lib/sh/tmpfile.c @@ -2,7 +2,7 @@ * tmpfile.c - functions to create and safely open temp files for the shell. */ -/* Copyright (C) 2000-2020,2022-2023 Free Software Foundation, Inc. +/* Copyright (C) 2000-2020,2022-2024 Free Software Foundation, Inc. This file is part of GNU Bash, the Bourne Again SHell. diff --git a/parse.y b/parse.y index 15e52dbc9..551e03d0d 100644 --- a/parse.y +++ b/parse.y @@ -1,6 +1,6 @@ /* parse.y - Yacc grammar for bash. */ -/* Copyright (C) 1989-2023 Free Software Foundation, Inc. +/* Copyright (C) 1989-2024 Free Software Foundation, Inc. This file is part of GNU Bash, the Bourne Again SHell. diff --git a/print_cmd.c b/print_cmd.c index 0886b5c2c..330223d38 100644 --- a/print_cmd.c +++ b/print_cmd.c @@ -1,6 +1,6 @@ /* print_command -- A way to make readable commands from a command tree. */ -/* Copyright (C) 1989-2023 Free Software Foundation, Inc. +/* Copyright (C) 1989-2024 Free Software Foundation, Inc. This file is part of GNU Bash, the Bourne Again SHell. diff --git a/redir.c b/redir.c index 65ddf2016..6c2f62d2e 100644 --- a/redir.c +++ b/redir.c @@ -1,6 +1,6 @@ /* redir.c -- Functions to perform input and output redirection. */ -/* Copyright (C) 1997-2023 Free Software Foundation, Inc. +/* Copyright (C) 1997-2024 Free Software Foundation, Inc. This file is part of GNU Bash, the Bourne Again SHell. diff --git a/shell.c b/shell.c index 7fb300ac0..add8b1cd3 100644 --- a/shell.c +++ b/shell.c @@ -1,6 +1,6 @@ /* shell.c -- GNU's idea of the POSIX shell specification. */ -/* Copyright (C) 1987-2023 Free Software Foundation, Inc. +/* Copyright (C) 1987-2024 Free Software Foundation, Inc. This file is part of GNU Bash, the Bourne Again SHell. diff --git a/subst.c b/subst.c index 331e2995d..ed7da9d2a 100644 --- a/subst.c +++ b/subst.c @@ -4,7 +4,7 @@ /* ``Have a little faith, there's magic in the night. You ain't a beauty, but, hey, you're alright.'' */ -/* Copyright (C) 1987-2023 Free Software Foundation, Inc. +/* Copyright (C) 1987-2024 Free Software Foundation, Inc. This file is part of GNU Bash, the Bourne Again SHell. @@ -1299,15 +1299,20 @@ extract_arithmetic_subst (const char *string, size_t *sindex) char * extract_process_subst (const char *string, char *starter, size_t *sindex, int xflags) { + char *ret; + char *xstr; #if 0 /* XXX - check xflags&SX_COMPLETE here? */ - return (extract_delimited_string (string, sindex, starter, "(", ")", SX_COMMAND)); + if (flags & SX_COMPLETE) + return (extract_delimited_string (string, sindex, starter, "(", ")", SX_COMMAND)); + else #else - char *xstr; - - xflags |= (no_longjmp_on_fatal_error ? SX_NOLONGJMP : 0); - xstr = (char *)string + *sindex; - return (xparse_dolparen (string, xstr, sindex, xflags)); + { + xflags |= (no_longjmp_on_fatal_error ? SX_NOLONGJMP : 0); + xstr = (char *)string + *sindex; + ret = xparse_dolparen (string, xstr, sindex, xflags); + return ret; + } #endif } #endif /* PROCESS_SUBSTITUTION */ @@ -1344,7 +1349,7 @@ extract_array_assignment_list (const char *string, size_t *sindex) static char * extract_delimited_string (const char *string, size_t *sindex, char *opener, char *alt_opener, char *closer, int flags) { - int c; + int c, xflags; size_t i, si, slen; char *t, *result; int pass_character, nesting_level, in_comment; @@ -1472,8 +1477,8 @@ extract_delimited_string (const char *string, size_t *sindex, char *opener, char if (c == '\'' || c == '"') { si = i + 1; - i = (c == '\'') ? skip_single_quoted (string, slen, si, 0) - : skip_double_quoted (string, slen, si, 0); + i = (c == '\'') ? skip_single_quoted (string, slen, si, flags) + : skip_double_quoted (string, slen, si, flags); continue; } @@ -6917,6 +6922,7 @@ function_substitute (char *string, int quoted, int flags) unwind_protect_pointer (this_shell_function); unwind_protect_pointer (this_shell_builtin); unwind_protect_pointer (current_builtin); + unwind_protect_pointer (currently_executing_command); unwind_protect_int (eof_encountered); add_unwind_protect (uw_pop_var_context, 0); add_unwind_protect (uw_maybe_restore_getopt_state, gs); @@ -6992,6 +6998,7 @@ function_substitute (char *string, int quoted, int flags) remove_quoted_escapes (string); + currently_executing_command = NULL; executing_funsub++; if (expand_aliases) expand_aliases = posixly_correct == 0; diff --git a/test.c b/test.c index 3d1a5693c..6967ef95d 100644 --- a/test.c +++ b/test.c @@ -2,7 +2,7 @@ /* Modified to run with the GNU shell Apr 25, 1988 by bfox. */ -/* Copyright (C) 1987-2023 Free Software Foundation, Inc. +/* Copyright (C) 1987-2024 Free Software Foundation, Inc. This file is part of GNU Bash, the Bourne Again SHell. diff --git a/variables.c b/variables.c index e54bd14bd..85bdf39aa 100644 --- a/variables.c +++ b/variables.c @@ -503,25 +503,18 @@ initialize_shell_variables (char **env, int privmode) # endif /* ARRAY_EXPORT */ #endif { - ro = 0; - /* If we processed a command-line option that caused SHELLOPTS to be - set, it may already be set (and read-only) by the time we process - the shell's environment. */ - if (/* posixly_correct &&*/ STREQ (name, "SHELLOPTS")) - { - temp_var = find_variable ("SHELLOPTS"); - ro = temp_var && readonly_p (temp_var); - if (temp_var) - VUNSETATTR (temp_var, att_readonly); - } + /* If we processed a command-line option that caused SHELLOPTS or + BASHOPTS to be set, it may already be set (and read-only) by the + time we process the shell's environment. */ + ro = STREQ (name, "SHELLOPTS") || STREQ (name, "BASHOPTS"); if (valid_identifier (name)) { - temp_var = bind_variable (name, string, 0); + temp_var = bind_variable (name, string, ro ? ASS_FORCE : 0); if (temp_var) { VSETATTR (temp_var, (att_exported | att_imported)); if (ro) - VSETATTR (temp_var, att_readonly); + VSETATTR (temp_var, att_readonly); /* just make sure */ } } else @@ -981,8 +974,8 @@ set_ppid (void) name = inttostr (getppid (), namebuf, sizeof(namebuf)); temp_var = find_variable ("PPID"); if (temp_var) - VUNSETATTR (temp_var, (att_readonly | att_exported)); - temp_var = bind_variable ("PPID", name, 0); + VUNSETATTR (temp_var, att_exported); + temp_var = bind_variable ("PPID", name, ASS_FORCE); VSETATTR (temp_var, (att_readonly | att_integer)); }