From 98300c940560d9d063b33e1bb17d9a96553a72a0 Mon Sep 17 00:00:00 2001 From: Chet Ramey Date: Tue, 26 Apr 2022 10:21:05 -0400 Subject: [PATCH] force using temp files for here documents with shell compatibility setting; fix small memleak in programmable completion --- CHANGES | 6 ++--- CHANGES-5.2 | 6 ++--- COMPAT | 7 ++++++ CWRU/CWRU.chlog | 17 +++++++++++++- lib/readline/doc/rltech.texi | 3 +++ lib/readline/examples/excallback.c | 4 ++++ lib/readline/examples/histexamp.c | 3 +++ lib/readline/examples/rl-callbacktest.c | 29 +++++++++++++++++++++++- lib/readline/examples/rl-callbacktest2.c | 3 +++ lib/readline/examples/rl.c | 8 +++++++ lib/readline/examples/rlcat.c | 8 +++++++ lib/readline/examples/rlptytest.c | 23 ++++++++++++++++--- lib/readline/examples/rltest.c | 8 +++++++ pcomplete.c | 1 + redir.c | 5 +++- subst.c | 4 +++- 16 files changed, 122 insertions(+), 13 deletions(-) diff --git a/CHANGES b/CHANGES index ed856182..69e0150d 100644 --- a/CHANGES +++ b/CHANGES @@ -291,10 +291,10 @@ h. The `unset' builtin now attempts to treat arguments as array subscripts i. There is a default value for $BASH_LOADABLES_PATH in config-top.h. j. Associative array assignment and certain instances of referencing (e.g., - `test -v' now allow `@' and `*' to be used as keys. + `test -v') now allow `@' and `*' to be used as keys. -k. Bash attempts to expand indexed array subscripts only once when executing - shell constructs and word expansions. +k. Bash attempts to expand indexed and associative array subscripts only + once when executing shell constructs and word expansions. l. The `unset' builtin allows a subscript of `@' or `*' to unset a key with that value for associative arrays instead of unsetting the entire array diff --git a/CHANGES-5.2 b/CHANGES-5.2 index e14f3b0f..eb5b9f30 100644 --- a/CHANGES-5.2 +++ b/CHANGES-5.2 @@ -291,10 +291,10 @@ h. The `unset' builtin now attempts to treat arguments as array subscripts i. There is a default value for $BASH_LOADABLES_PATH in config-top.h. j. Associative array assignment and certain instances of referencing (e.g., - `test -v' now allow `@' and `*' to be used as keys. + `test -v') now allow `@' and `*' to be used as keys. -k. Bash attempts to expand indexed array subscripts only once when executing - shell constructs and word expansions. +k. Bash attempts to expand indexed and associative array subscripts only + once when executing shell constructs and word expansions. l. The `unset' builtin allows a subscript of `@' or `*' to unset a key with that value for associative arrays instead of unsetting the entire array diff --git a/COMPAT b/COMPAT index aa25f19d..091371cd 100644 --- a/COMPAT +++ b/COMPAT @@ -550,6 +550,9 @@ compat50 (set using BASH_COMPAT) printed an informational message to that effect even when writing output in a format that can be reused as input (-l). Bash-5.1 suppresses that message if -l is supplied + - Bash-5.1 and later use pipes for here-documents and here-strings if + they are smaller than the pipe capacity. If the shell compatibility + level is set to 50 or lower, it reverts to using temporary files. compat51 (set using BASH_COMPAT) - The `unset' builtin will unset the array a given an argument like @@ -560,6 +563,10 @@ compat51 (set using BASH_COMPAT) for statement can be expanded more than once - expressions used as arguments to arithmetic operators in the [[ conditional command can be expanded more than once + - indexed and associative array subscripts used as arguments to the + operators in the [[ conditional command (e.g., `[[ -v') can be + expanded more than once. Bash-5.2 behaves as if the + `assoc_expand_once' option were enabled. - the expressions in substring parameter brace expansion can be expanded more than once - the expressions in the $(( ... )) word expansion can be expanded diff --git a/CWRU/CWRU.chlog b/CWRU/CWRU.chlog index 27aa30b1..8f95dcae 100644 --- a/CWRU/CWRU.chlog +++ b/CWRU/CWRU.chlog @@ -2870,7 +2870,7 @@ subst.c - parameter_brace_expand: when expanding an indirect variable, extend the special case for array[@] and array[*] (set -u/no positional parameters, obeying the baroque quoting rules) to the value of the - indirection. Report amd fix from konsolebox + indirection. Report and fix from konsolebox 12/31 ----- @@ -3556,3 +3556,18 @@ lib/sh/zmapfd.c lib/sh/zgetline.c - zgetline: use size_t instead of int for local length and indexing variables + + 4/20 + ---- +pcomplete.c + - init_itemlist_from_varlist: free VLIST after assigning it from + *SVFUNC and after we get the variable names and values out of it. + Report from Robert E. Griffith + + 4/25 + ---- +redir.c + - here_document_to_fd: if the shell compatibility level is bash-5.0 or + earlier, use tempfiles for all here-documents and here-strings. From + a bug-bash discussion started by Sam Liddicott + diff --git a/lib/readline/doc/rltech.texi b/lib/readline/doc/rltech.texi index 6f7ffb93..fe64a42c 100644 --- a/lib/readline/doc/rltech.texi +++ b/lib/readline/doc/rltech.texi @@ -2368,6 +2368,7 @@ history list. #include #include #include +#include #if defined (HAVE_STRING_H) # include @@ -2448,6 +2449,8 @@ main (argc, argv) @{ char *line, *s; + setlocale (LC_ALL, ""); + progname = argv[0]; initialize_readline (); /* Bind our completer. */ diff --git a/lib/readline/examples/excallback.c b/lib/readline/examples/excallback.c index 4206acfc..923c9238 100644 --- a/lib/readline/examples/excallback.c +++ b/lib/readline/examples/excallback.c @@ -50,6 +50,8 @@ Copyright (C) 1999 Jeff Solomon #include #include /* xxx - should make this more general */ +#include + #ifdef READLINE_LIBRARY # include "readline.h" #else @@ -104,6 +106,8 @@ main() { fd_set fds; + setlocale (LC_ALL, ""); + /* Adjust the terminal slightly before the handler is installed. Disable * canonical mode processing and set the input character time flag to be * non-blocking. diff --git a/lib/readline/examples/histexamp.c b/lib/readline/examples/histexamp.c index 3b43674f..309d769b 100644 --- a/lib/readline/examples/histexamp.c +++ b/lib/readline/examples/histexamp.c @@ -27,8 +27,11 @@ # include #endif +#include +#include #include +int main (argc, argv) int argc; char **argv; diff --git a/lib/readline/examples/rl-callbacktest.c b/lib/readline/examples/rl-callbacktest.c index 0f00e57c..4373398b 100644 --- a/lib/readline/examples/rl-callbacktest.c +++ b/lib/readline/examples/rl-callbacktest.c @@ -7,9 +7,15 @@ #include #include +#include + #include #include +#ifdef HAVE_LOCALE_H +# include +#endif + /* Standard readline include files. */ #if defined (READLINE_LIBRARY) # include "readline.h" @@ -22,10 +28,19 @@ extern int errno; static void cb_linehandler (char *); +static void signandler (int); -int running; +int running, sigwinch_received; const char *prompt = "rltest$ "; +/* Handle SIGWINCH and window size changes when readline is not active and + reading a character. */ +static void +sighandler (int sig) +{ + sigwinch_received = 1; +} + /* Callback function called for each line when accept-line executed, EOF seen, or EOF character read. This sets a flag and returns; it could also call exit(3). */ @@ -60,6 +75,11 @@ main (int c, char **v) fd_set fds; int r; + setlocale (LC_ALL, ""); + + /* Handle SIGWINCH */ + signal (SIGWINCH, sighandler); + /* Install the line handler. */ rl_callback_handler_install (prompt, cb_linehandler); @@ -80,6 +100,13 @@ main (int c, char **v) rl_callback_handler_remove (); break; } + if (sigwinch_received) + { + rl_resize_terminal (); + sigwinch_received = 0; + } + if (r < 0) + continue; if (FD_ISSET (fileno (rl_instream), &fds)) rl_callback_read_char (); diff --git a/lib/readline/examples/rl-callbacktest2.c b/lib/readline/examples/rl-callbacktest2.c index 2525b707..dfaf9675 100644 --- a/lib/readline/examples/rl-callbacktest2.c +++ b/lib/readline/examples/rl-callbacktest2.c @@ -10,6 +10,7 @@ #include +#include #include /* Standard readline include files. */ @@ -125,6 +126,8 @@ main (int c, char **v) { char *p; + setlocale (LC_ALL, ""); + running = 1; rl_catch_signals = 1; diff --git a/lib/readline/examples/rl.c b/lib/readline/examples/rl.c index a5cf276c..39e5b8eb 100644 --- a/lib/readline/examples/rl.c +++ b/lib/readline/examples/rl.c @@ -38,6 +38,10 @@ extern void exit(); #endif +#ifdef HAVE_LOCALE_H +# include +#endif + #if defined (READLINE_LIBRARY) # include "posixstat.h" # include "readline.h" @@ -93,6 +97,10 @@ main (argc, argv) else progname++; +#ifdef HAVE_SETLOCALE + setlocale (LC_ALL, ""); +#endif + /* defaults */ prompt = "readline$ "; fd = nch = 0; diff --git a/lib/readline/examples/rlcat.c b/lib/readline/examples/rlcat.c index b4942413..aabe0ca3 100644 --- a/lib/readline/examples/rlcat.c +++ b/lib/readline/examples/rlcat.c @@ -45,6 +45,10 @@ extern void exit(); #endif +#ifdef HAVE_LOCALE_H +# include +#endif + #ifndef errno extern int errno; #endif @@ -79,6 +83,10 @@ main (argc, argv) char *temp; int opt, Vflag, Nflag; +#ifdef HAVE_SETLOCALE + setlocale (LC_ALL, ""): +#endif + progname = strrchr(argv[0], '/'); if (progname == 0) progname = argv[0]; diff --git a/lib/readline/examples/rlptytest.c b/lib/readline/examples/rlptytest.c index 79257db4..0008dd1f 100644 --- a/lib/readline/examples/rlptytest.c +++ b/lib/readline/examples/rlptytest.c @@ -19,12 +19,16 @@ #include -#if 0 /* LINUX */ +#if 1 /* LINUX */ #include #else #include #endif +#ifdef HAVE_LOCALE_H +# include +#endif + #ifdef READLINE_LIBRARY # include "readline.h" #else @@ -48,6 +52,13 @@ sigint (s) exit (0); } +void +sigwinch (s) + int s; +{ + rl_resize_terminal (); +} + static int user_input() { @@ -308,6 +319,11 @@ int main() { int val; + +#ifdef HAVE_SETLOCALE + setlocale (LC_ALL, ""); +#endif + val = openpty (&masterfd, &slavefd, NULL, NULL, NULL); if (val == -1) return -1; @@ -316,6 +332,9 @@ main() if (val == -1) return -1; + signal (SIGWINCH, sigwinch); + signal (SIGINT, sigint); + val = init_readline (slavefd, slavefd); if (val == -1) return -1; @@ -324,8 +343,6 @@ main() if (val == -1) return -1; - signal (SIGINT, sigint); - val = main_loop (); tty_reset (STDIN_FILENO); diff --git a/lib/readline/examples/rltest.c b/lib/readline/examples/rltest.c index 65abe87c..8b7c00c8 100644 --- a/lib/readline/examples/rltest.c +++ b/lib/readline/examples/rltest.c @@ -36,6 +36,10 @@ extern void exit(); #endif +#ifdef HAVE_LOCALE_H +# include +#endif + #ifdef READLINE_LIBRARY # include "readline.h" # include "history.h" @@ -52,6 +56,10 @@ main () char *temp, *prompt; int done; +#ifdef HAVE_SETLOCALE + setlocale (LC_ALL, ""); +#endif + temp = (char *)NULL; prompt = "readline$ "; done = 0; diff --git a/pcomplete.c b/pcomplete.c index 62012534..9612406d 100644 --- a/pcomplete.c +++ b/pcomplete.c @@ -414,6 +414,7 @@ init_itemlist_from_varlist (itp, svfunc) sl->list[i] = savestring (vlist[i]->name); sl->list[sl->list_len = n] = (char *)NULL; itp->slist = sl; + free (vlist); } static int diff --git a/redir.c b/redir.c index 5266b9f4..8369adcc 100644 --- a/redir.c +++ b/redir.c @@ -460,7 +460,10 @@ here_document_to_fd (redirectee, ri) return fd; } -#if defined (HEREDOC_PIPESIZE) + if (shell_compatibility_level <= 50) + goto use_tempfile; + +#if HEREDOC_PIPESIZE /* Try to use a pipe internal to this process if the document is shorter than the system's pipe capacity (computed at build time). We want to write the entire document without write blocking. */ diff --git a/subst.c b/subst.c index 36d004cd..394b5615 100644 --- a/subst.c +++ b/subst.c @@ -4095,7 +4095,9 @@ remove_backslashes (string) to the != or == operator, and should be treated as a pattern. In this case, we quote the string specially for the globbing code. If SPECIAL is 2, this is an rhs argument for the =~ operator, and should - be quoted appropriately for regcomp/regexec. The caller is responsible + be quoted appropriately for regcomp/regexec. If SPECIAL is 3, this is + an array subscript and should be quoted after expansion so it's only + expanded once (Q_ARITH). The caller is responsible for removing the backslashes if the unquoted word is needed later. In any case, since we don't perform word splitting, we need to do quoted null character removal. */