]> git.ipfire.org Git - thirdparty/bash.git/commitdiff
force using temp files for here documents with shell compatibility setting; fix small...
authorChet Ramey <chet.ramey@case.edu>
Tue, 26 Apr 2022 14:21:05 +0000 (10:21 -0400)
committerChet Ramey <chet.ramey@case.edu>
Tue, 26 Apr 2022 14:21:05 +0000 (10:21 -0400)
16 files changed:
CHANGES
CHANGES-5.2
COMPAT
CWRU/CWRU.chlog
lib/readline/doc/rltech.texi
lib/readline/examples/excallback.c
lib/readline/examples/histexamp.c
lib/readline/examples/rl-callbacktest.c
lib/readline/examples/rl-callbacktest2.c
lib/readline/examples/rl.c
lib/readline/examples/rlcat.c
lib/readline/examples/rlptytest.c
lib/readline/examples/rltest.c
pcomplete.c
redir.c
subst.c

diff --git a/CHANGES b/CHANGES
index ed85618298106b99d7d632ee5fb4382deaf8a341..69e0150d8e6a5f8b6b66f90481bd39780e80e5d3 100644 (file)
--- 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
index e14f3b0f40c754a5815ebca1c6444d0d0cfac935..eb5b9f3024d12385a4b933ee7d08e4f0bc7488e0 100644 (file)
@@ -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 aa25f19d86767e7e4d90ad28823157e3e9e701c5..091371cd21a56926b2f7d22814205279b181a8d0 100644 (file)
--- 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
index 27aa30b17a0f1e78440e3165c22c7430fe9ba93a..8f95dcae00eb686c2a55a640652a624ea6e3e534 100644 (file)
@@ -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 <konsolebox@gmail.com>
+         indirection. Report and fix from konsolebox <konsolebox@gmail.com>
 
                                   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 <bobg@junga.com>
+
+                                  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 <sam@liddicott.com>
+
index 6f7ffb931a54bc0cd74174b5e844e74d848f1d88..fe64a42cbfd1bc76d22fa615ac809b79655cb4b1 100644 (file)
@@ -2368,6 +2368,7 @@ history list.
 #include <fcntl.h>
 #include <stdio.h>
 #include <errno.h>
+#include <locale.h>
 
 #if defined (HAVE_STRING_H)
 #  include <string.h>
@@ -2448,6 +2449,8 @@ main (argc, argv)
 @{
   char *line, *s;
 
+  setlocale (LC_ALL, "");
+
   progname = argv[0];
 
   initialize_readline ();      /* Bind our completer. */
index 4206acfca4a518c8081d1e5389e2fdcb1b51bb8c..923c9238b6ecaf9d799171ec6aa9002f4089c1a5 100644 (file)
@@ -50,6 +50,8 @@ Copyright (C) 1999 Jeff Solomon
 #include <stdio.h>
 #include <termios.h>   /* xxx - should make this more general */
 
+#include <locale.h>
+
 #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.
index 3b43674f79dd9142a7e4ae798a84fdecd7a684ac..309d769b3845e254132dab0aac3fb11050b4e150 100644 (file)
 #  include <readline/history.h>
 #endif
 
+#include <unistd.h>
+#include <stdlib.h>
 #include <string.h>
 
+int
 main (argc, argv)
      int argc;
      char **argv;
index 0f00e57c564e6b98b58f920cde02333a25157d8c..4373398bd84c8a0e3c5654eaf58b141c1ce407c2 100644 (file)
@@ -7,9 +7,15 @@
 #include <sys/types.h>
 #include <sys/select.h>
 
+#include <signal.h>
+
 #include <errno.h>
 #include <stdio.h>
 
+#ifdef HAVE_LOCALE_H
+#  include <locale.h>
+#endif
+
 /* Standard readline include files. */
 #if defined (READLINE_LIBRARY)
 #  include "readline.h"
 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 ();
index 2525b7071e46c7d74f30badd8000d7d97d25c822..dfaf9675587d918479806df607533015b59f68f8 100644 (file)
@@ -10,6 +10,7 @@
 
 #include <signal.h>
 
+#include <locale.h>
 #include <stdio.h>
 
 /* Standard readline include files. */
@@ -125,6 +126,8 @@ main (int c, char **v)
 {
   char *p;
 
+  setlocale (LC_ALL, "");
+
   running = 1;
   rl_catch_signals = 1;
 
index a5cf276cb943afcf88a12691c2d7c160dcb11262..39e5b8ebb5d1be6b748a9d8bab3d3feb190e0784 100644 (file)
 extern void exit();
 #endif
 
+#ifdef HAVE_LOCALE_H
+#  include <locale.h>
+#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;
index b4942413f8bebb6d08b83e035ce7dde3a9c52bf7..aabe0ca3e98673179a77d0f647122639e3028fa9 100644 (file)
 extern void exit();
 #endif
 
+#ifdef HAVE_LOCALE_H
+#  include <locale.h>
+#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];
index 79257db4005f9b477d15a9216783960931615f65..0008dd1fca9331ed07952aceca0d5f770777e2dd 100644 (file)
 
 #include <signal.h>
 
-#if 0  /* LINUX */
+#if 1  /* LINUX */
 #include <pty.h>
 #else
 #include <util.h>
 #endif
 
+#ifdef HAVE_LOCALE_H
+#  include <locale.h>
+#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);
index 65abe87cc044d39175d58408d60ad27674c3e8be..8b7c00c8c49a0e7f071c09f1d93d818b597afd23 100644 (file)
 extern void exit();
 #endif
 
+#ifdef HAVE_LOCALE_H
+#  include <locale.h>
+#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;
index 6201253471d1a980b05e1ee020b41d32dfc0b8b7..9612406d9e02e50a78edcccd9bb62687c57a6319 100644 (file)
@@ -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 5266b9f46bacd0ba2fe56758be99e2da1676d3df..8369adccbd6bc0389aa2d6cc1d493c462ca62ad3 100644 (file)
--- 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 36d004cd084b049d246b7f5291532e4345e80e28..394b56151fe62447cc68dff87bcbd08e959c24c3 100644 (file)
--- 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. */