]> git.ipfire.org Git - thirdparty/bash.git/commitdiff
size_t changes for multibyte characters; fix for running debug trap in asynchronous...
authorChet Ramey <chet.ramey@case.edu>
Fri, 28 Jun 2024 18:16:29 +0000 (14:16 -0400)
committerChet Ramey <chet.ramey@case.edu>
Fri, 28 Jun 2024 18:16:29 +0000 (14:16 -0400)
20 files changed:
CWRU/CWRU.chlog
builtins/evalfile.c
builtins/printf.def
configure
configure.ac
doc/bash.1
doc/bashref.texi
lib/readline/complete.c
lib/readline/display.c
lib/readline/examples/excallback.c
lib/readline/examples/histexamp.c
lib/readline/examples/manexamp.c
lib/readline/funmap.c
lib/readline/nls.c
lib/readline/text.c
lib/readline/util.c
lib/sh/casemod.c
lib/sh/zwrite.c
support/man2html.c
trap.c

index bcbb643727ccf02998756994771407ea743ea55e..b716927aadcf2b516005402fa63f982cc5168d77 100644 (file)
@@ -9677,3 +9677,47 @@ pathexp.c
          any non-digits sort after all-digit names and are sorted
          lexicographically.
          Inspired by a discussion with Robert Elz <kre@munnari.oz.au>
+
+                                  6/21
+                                  ----
+lib/readline/text.c
+       - rl_change_case: make mlen size_t to assign the return value from
+         wcrtomb; change the tests of < 0 to use MB_INVALIDCH.
+         Report from Siteshwar Vashisht <svashisht@redhat.com>
+
+                                  6/26
+                                  ----
+trap.c
+       - run_debug_trap: give the terminal back to pipeline_pgrp only if
+         job_control is enabled; that's the only way the trap command would
+         have given it to a different process group
+         Fixes bug reported by Mark March <march@systempad.cloud>
+
+                                  6/27
+                                  ----
+configure.ac
+       - remove support for cached files for cross-compiling; it's too hard
+         to keep them up-to-date without access to the platforms
+
+                                  6/28
+                                  ----
+lib/readline/util.c
+       - _rl_audit_tty: make sure to close fd before returning on error
+
+lib/sh/casemod.c
+       - sh_modcase: use size_t variable as return value for wcrtomb; check
+         for invalid wide char and copy all characters in the multibyte
+         character as-is if it is
+
+lib/sh/zwrite.c
+       - zwrite: use size_t and ssize_t variables
+
+builtins/evalfile.c
+       - _evalfile: use size_t variable for return value from strlen()
+
+lib/readline/funmap.c
+       - rl_funmap_names: don't bother calling qsort if result doesn't have
+         any entries
+
+         All from a report by Siteshwar Vashisht <svashisht@redhat.com>
+
index 14a8488c8a7bed1c1c2e5010c5a39fef0663ec4b..9521934e59197eaa0f7dd2edbe1a9ba49e9a6b37 100644 (file)
@@ -78,7 +78,8 @@ _evalfile (const char *filename, int flags)
 {
   volatile int old_interactive;
   procenv_t old_return_catch;
-  int return_val, fd, result, pflags, i, nnull;
+  int return_val, fd, result, pflags, nnull;
+  size_t i;
   ssize_t nr;                  /* return value from read(2) */
   char *string;
   struct stat finfo;
@@ -101,19 +102,19 @@ _evalfile (const char *filename, int flags)
   do
     {
       fd = open (filename, O_RDONLY);
-      i = errno;
-      if (fd < 0 && i == EINTR)
+      result = errno;
+      if (fd < 0 && result == EINTR)
         QUIT;
-      errno = i;
+      errno = result;
     }
   while (fd < 0 && errno == EINTR && (flags & FEVAL_RETRY));
 
   if (fd < 0 || (fstat (fd, &finfo) == -1))
     {
-      i = errno;
+      result = errno;
       if (fd >= 0)
        close (fd);
-      errno = i;
+      errno = result;
 
 file_error_and_exit:
       if (((flags & FEVAL_ENOENTOK) == 0) || errno != ENOENT)
index 4d663225a3c47d16af55f7255fbbb6841219b4a1..6549e7186ff41deb432f72341a41669eae1a950e 100644 (file)
@@ -1515,8 +1515,7 @@ asciicode (void)
   register intmax_t ch;
 #if defined (HANDLE_MULTIBYTE)
   wchar_t wc;
-  size_t slen;
-  int mblength;
+  size_t slen, mblength;
 #endif
   DECLARE_MBSTATE;
 
@@ -1524,7 +1523,7 @@ asciicode (void)
   slen = strlen (garglist->word->word+1);
   wc = 0;
   mblength = mbrtowc (&wc, garglist->word->word+1, slen, &state);
-  if (mblength > 0)
+  if (MB_INVALIDCH (mblength) == 0)
     ch = wc;           /* XXX */
   else
 #endif
index 6977651a01b2a6c3a57774e865cf58e1dad050da..285b739636b99d64d7be0a5ab44a3f54c2cfeeab 100755 (executable)
--- a/configure
+++ b/configure
@@ -1,5 +1,5 @@
 #! /bin/sh
-# From configure.ac for Bash 5.3, version 5.065.
+# From configure.ac for Bash 5.3, version 5.066.
 # Guess values for system-dependent variables and create Makefiles.
 # Generated by GNU Autoconf 2.72 for bash 5.3-alpha.
 #
@@ -5330,30 +5330,30 @@ SIGNAMES_H=lsignames.h
 
 CROSS_COMPILE=
 if test "x$cross_compiling" = "xyes"; then
-    case "${host}" in
-    *-cygwin*)
-       cross_cache=${srcdir}/cross-build/cygwin32.cache
-       ;;
-    *-msys*)
-       cross_cache=${srcdir}/cross-build/msys32.cache
-       ;;
-    *-mingw*)
-       cross_cache=${srcdir}/cross-build/cygwin32.cache
-       ;;
-    i[3456]86-*-beos*)
-       cross_cache=${srcdir}/cross-build/x86-beos.cache
-       ;;
-    *-qnx*)
-       cross_cache=${srcdir}/cross-build/qnx.cache
-       ;;
-    *) echo "configure: cross-compiling for $host is not supported" >&2
-       ;;
-    esac
-    if test -n "${cross_cache}" && test -r "${cross_cache}"; then
-       echo "loading cross-build cache file ${cross_cache}"
-       . ${cross_cache}
-    fi
-    unset cross_cache
+#    case "${host}" in
+#    *-cygwin*)
+#      cross_cache=${srcdir}/cross-build/cygwin32.cache
+#      ;;
+#    *-msys*)
+#      cross_cache=${srcdir}/cross-build/msys32.cache
+#      ;;
+#    *-mingw*)
+#      cross_cache=${srcdir}/cross-build/cygwin32.cache
+#      ;;
+#    i[[3456]]86-*-beos*)
+#      cross_cache=${srcdir}/cross-build/x86-beos.cache
+#      ;;
+#   *-qnx*)
+#      cross_cache=${srcdir}/cross-build/qnx.cache
+#      ;;
+#    *)        echo "configure: cross-compiling for $host is not supported" >&2
+#      ;;
+#    esac
+#    if test -n "${cross_cache}" && test -r "${cross_cache}"; then
+#      echo "loading cross-build cache file ${cross_cache}"
+#      . ${cross_cache}
+#    fi
+#    unset cross_cache
     SIGNAMES_O='signames.o'
     CROSS_COMPILE='-DCROSS_COMPILING'
 
index fe9306f461b65a93126639bd4aa027a24da0c673..b556b388d65ee025dc8175b68cc6a2c3959e36ec 100644 (file)
@@ -21,7 +21,7 @@ dnl Process this file with autoconf to produce a configure script.
 #   You should have received a copy of the GNU General Public License
 #   along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
-AC_REVISION([for Bash 5.3, version 5.065])dnl
+AC_REVISION([for Bash 5.3, version 5.066])dnl
 
 define(bashvers, 5.3)
 define(relstatus, alpha)
@@ -460,30 +460,30 @@ dnl Set SIGNAMES_H based on whether or not we're cross-compiling.
 
 CROSS_COMPILE=
 if test "x$cross_compiling" = "xyes"; then
-    case "${host}" in
-    *-cygwin*)
-       cross_cache=${srcdir}/cross-build/cygwin32.cache
-       ;;
-    *-msys*)
-       cross_cache=${srcdir}/cross-build/msys32.cache
-       ;;
-    *-mingw*)
-       cross_cache=${srcdir}/cross-build/cygwin32.cache
-       ;;
-    i[[3456]]86-*-beos*)
-       cross_cache=${srcdir}/cross-build/x86-beos.cache
-       ;;
-    *-qnx*)
-       cross_cache=${srcdir}/cross-build/qnx.cache
-       ;;
-    *) echo "configure: cross-compiling for $host is not supported" >&2
-       ;;
-    esac
-    if test -n "${cross_cache}" && test -r "${cross_cache}"; then
-       echo "loading cross-build cache file ${cross_cache}"
-       . ${cross_cache}
-    fi
-    unset cross_cache
+#    case "${host}" in
+#    *-cygwin*)
+#      cross_cache=${srcdir}/cross-build/cygwin32.cache
+#      ;;
+#    *-msys*)
+#      cross_cache=${srcdir}/cross-build/msys32.cache
+#      ;;
+#    *-mingw*)
+#      cross_cache=${srcdir}/cross-build/cygwin32.cache
+#      ;;
+#    i[[3456]]86-*-beos*)
+#      cross_cache=${srcdir}/cross-build/x86-beos.cache
+#      ;;
+#   *-qnx*)
+#      cross_cache=${srcdir}/cross-build/qnx.cache
+#      ;;
+#    *)        echo "configure: cross-compiling for $host is not supported" >&2
+#      ;;
+#    esac
+#    if test -n "${cross_cache}" && test -r "${cross_cache}"; then
+#      echo "loading cross-build cache file ${cross_cache}"
+#      . ${cross_cache}
+#    fi
+#    unset cross_cache
     SIGNAMES_O='signames.o'
     CROSS_COMPILE='-DCROSS_COMPILING'
     AC_SUBST(CROSS_COMPILE)
index 328a609442189662d5b06ad35af0c7e864f0c5f7..c1df375434b78459b24e01c3237f1f2019d49f90 100644 (file)
@@ -9946,8 +9946,8 @@ any supplied field width and precision in terms of characters, not bytes.
 .PP
 Arguments to non-string format specifiers are treated as C constants,
 except that a leading plus or minus sign is allowed, and if the leading
-character is a single or double quote, the value is the ASCII value of
-the following character.
+character is a single or double quote, the value is the numeric value of
+the following character, using the current locale.
 .PP
 The \fIformat\fP is reused as necessary to consume all of the \fIarguments\fP.
 If the \fIformat\fP requires more \fIarguments\fP than are supplied, the
index 26ea6d8c9840b99d4c27fa22bfc4dbfe9e53a28e..2e52db8f324ca2884c552442a30dbf4607c1b423 100644 (file)
@@ -5091,8 +5091,8 @@ identically to the %b format specifier if it's supplied.
 
 Arguments to non-string format specifiers are treated as C language constants,
 except that a leading plus or minus sign is allowed, and if the leading
-character is a single or double quote, the value is the ASCII value of
-the following character.
+character is a single or double quote, the value is the numeric value of
+the following character, using the current locale.
 
 The @var{format} is reused as necessary to consume all of the @var{arguments}.
 If the @var{format} requires more @var{arguments} than are supplied, the
index cae21cdbdb7afda6689de4036f1d02ec0e474303..76bc252ca10054a388441029e188ccc575b2b18a 100644 (file)
@@ -1362,7 +1362,6 @@ compute_lcd_of_matches (char **match_list, int matches, const char *text)
   size_t si1, si2;
   size_t len1, len2;
 #if defined (HANDLE_MULTIBYTE)
-  int v;
   size_t v1, v2;
   mbstate_t ps1, ps2;
   WCHAR_T wc1, wc2;
index 7fdf23bdcb033dff3c884c66cfa0435825b99cf8..aff66ec35bf61f94b094199b414cc1823134edd6 100644 (file)
@@ -1732,7 +1732,7 @@ update_line (char *old, char *old_face, char *new, char *new_face, int current_l
 {
   char *ofd, *ols, *oe, *nfd, *nls, *ne;
   char *ofdf, *nfdf, *olsf, *nlsf;
-  int temp, lendiff, wsatend, od, nd, twidth, o_cpos;
+  int temp, lendiff, wsatend, od, nd, o_cpos;
   int current_invis_chars;
   int col_lendiff, col_temp;
   int bytes_to_insert;
@@ -1863,7 +1863,7 @@ update_line (char *old, char *old_face, char *new, char *new_face, int current_l
             _rl_output_some_chars below. */
          if (newwidth > 0)
            {
-             int count, i, j;
+             int i, j;
              char *optr;
 
              puts_face (new, new_face, newbytes);
index 04ecb140828fcf8e46a4b4ab27320359c0524e68..e8839d2686bbf61c06e9f0b043b93541b90d21cc 100644 (file)
@@ -19,7 +19,7 @@ My example shows how, using the alternate interface, you can
 interactively change the prompt (which is very nice imo). Also, I
 point out that you must roll your own terminal setting when using the
 alternate interface because readline depreps (using your parlance) the
-terminal while in the user callback. I try to demostrate what I mean
+terminal while in the user callback. I try to demonstrate what I mean
 with an example. I've included the program below.
 
 To compile, I just put the program in the examples directory and made
@@ -72,7 +72,7 @@ Copyright (C) 1999 Jeff Solomon
  * alternate interface. The first is the ability to interactively change the
  * prompt, which can't be done using the regular interface since rl_prompt is
  * read-only.
- * 
+ *
  * The second feature really highlights a subtle point when using the alternate
  * interface. That is, readline will not alter the terminal when inside your
  * callback handler. So let's so, your callback executes a user command that
index 2e946acac30bfd27605271e60c795b1978f951e0..d592b7e10fbe1ceaeca75f5763ae4168b20253c6 100644 (file)
@@ -110,7 +110,7 @@ main (int argc, char **argv)
          int which;
          if ((sscanf (line + 6, "%d", &which)) == 1)
            {
-             HIST_ENTRY *entry = remove_history (which);
+             HIST_ENTRY *entry = remove_history (which - history_base);
              if (!entry)
                fprintf (stderr, "No such entry %d\n", which);
              else
index c8e11d5c83a76ea812d052eb91e04517d42d8800..ce33877f2f454a42e1e6c2dc311ffb926e9d14b9 100644 (file)
@@ -94,16 +94,8 @@ invert_case_line (int count, int key)
 
   start = rl_point;
 
-  if (count < 0)
-    {
-      direction = -1;
-      count = -count;
-    }
-  else
-    direction = 1;
-      
   /* Find the end of the range to modify. */
-  end = start + (count * direction);
+  end = start + count;
 
   /* Force it to be within range. */
   if (end > rl_end)
@@ -111,6 +103,14 @@ invert_case_line (int count, int key)
   else if (end < 0)
     end = -1;
 
+  if (start == end)
+    return 0;
+
+  /* For positive arguments, put point after the last changed character. For
+     negative arguments, put point before the last changed character. */
+  rl_point = end;
+
+  /* Swap start and end if we are moving backwards */
   if (start > end)
     {
       int temp = start;
@@ -118,14 +118,11 @@ invert_case_line (int count, int key)
       end = temp;
     }
 
-  if (start == end)
-    return 0;
-
   /* Tell readline that we are modifying the line, so save the undo
      information. */
   rl_modifying (start, end);
 
-  for (; start != end; start += direction)
+  for (; start != end; start++)
     {
       if (_rl_uppercase_p (rl_line_buffer[start]))
        rl_line_buffer[start] = _rl_to_lower (rl_line_buffer[start]);
@@ -133,7 +130,5 @@ invert_case_line (int count, int key)
        rl_line_buffer[start] = _rl_to_upper (rl_line_buffer[start]);
     }
 
-  /* Move point to on top of the last character changed. */
-  rl_point = end - direction;
   return 0;
 }
index 548cfb572396de58a392adc765930df86395de82..28af3642c8a2c36358ea2951aab7def8964de6ef 100644 (file)
@@ -265,6 +265,7 @@ rl_funmap_names (void)
       result[result_index + 1] = (char *)NULL;
     }
 
-  qsort (result, result_index, sizeof (char *), (QSFUNC *)_rl_qsort_string_compare);
+  if (result)
+    qsort (result, result_index, sizeof (char *), (QSFUNC *)_rl_qsort_string_compare);
   return (result);
 }
index 8c027d6be500d06d90a7549e70127c3ba16093a6..e04991dab7a6fe5a18c6cee4c593f7981d5e904d 100644 (file)
@@ -107,12 +107,13 @@ static int
 utf8locale (char *lspec)
 {
   char *cp;
-  size_t len;
 
 #if HAVE_LANGINFO_CODESET
   cp = nl_langinfo (CODESET);
   return (STREQ (cp, "UTF-8") || STREQ (cp, "utf8"));
 #else
+  size_t len;
+
   cp = find_codeset (lspec, &len);
 
   if (cp == 0 || len < 4 || len > 5)
index bb5655d2afd30bd0d8417aa63ad38ddbb7dfff2f..e8d4f5f65b4112222f074a6873b1c466619a57f9 100644 (file)
@@ -1453,8 +1453,7 @@ rl_change_case (int count, int op)
 #if defined (HANDLE_MULTIBYTE)
   WCHAR_T wc, nwc;
   char mb[MB_LEN_MAX+1];
-  int mlen;
-  size_t m;
+  size_t m, mlen;
   mbstate_t mps;
 #endif
 
@@ -1532,12 +1531,13 @@ change_singlebyte:
 
              memset (&ts, 0, sizeof (mbstate_t));
              mlen = WCRTOMB (mb, nwc, &ts);
-             if (mlen < 0)
+             
+             if (MB_INVALIDCH (mlen))
                {
                  nwc = wc;
                  memset (&ts, 0, sizeof (mbstate_t));
                  mlen = WCRTOMB (mb, nwc, &ts);
-                 if (mlen < 0)         /* should not happen */
+                 if (MB_INVALIDCH (mlen))              /* should not happen */
                    strncpy (mb, rl_line_buffer + start, mlen = m);
                }
              if (mlen > 0)
index 2a247034b809747c35bc3f4dfb42096f4ea85619..2bcc776aeb15a01266341339d86eb21f1ee6d4b5 100644 (file)
@@ -536,7 +536,10 @@ _rl_audit_tty (char *string)
   size = strlen (string) + 1;
 
   if (NLMSG_SPACE (size) > MAX_AUDIT_MESSAGE_LENGTH)
-    return;
+    {
+      close (fd);
+      return;
+    }
 
   memset (&req, 0, sizeof(req));
   req.nlh.nlmsg_len = NLMSG_SPACE (size);
index 6bef458636636e95d670949a1f2f27ac8d04b265..acf5759c5db824e55a5aac730fce77be801ba34c 100644 (file)
@@ -106,8 +106,7 @@ sh_modcase (const char *string, char *pat, int flags)
 #if defined (HANDLE_MULTIBYTE)
   wchar_t nwc;
   char mb[MB_LEN_MAX+1];
-  int mlen;
-  size_t m;
+  size_t m, mlen;
   mbstate_t state;
 #endif
 
@@ -249,8 +248,9 @@ singlebyte:
          else
            {
              mlen = wcrtomb (mb, nwc, &state);
-             if (mlen > 0)
-               mb[mlen] = '\0';
+             if (MB_INVALIDCH (mlen))
+               strncpy (mb, string + start, mlen = m);                 
+             mb[mlen] = '\0';
              /* Don't assume the same width */
              strncpy (ret + retind, mb, mlen);
              retind += mlen;
index 54acc651eeaa5e3e5b1f7ae8458e29697d8e320b..0cea7f912c5d17947d2e77af120798807f731d91 100644 (file)
@@ -38,7 +38,9 @@ extern int errno;
 int
 zwrite (int fd, char *buf, size_t nb)
 {
-  int n, i, nt;
+  int nt;
+  size_t n;
+  ssize_t i;
 
   for (n = nb, nt = 0;;)
     {
index 097f48ee5beb7d2444600ab9103320805961611c..954b91327f56b7123552b60aff343c927a4b3170 100644 (file)
@@ -818,7 +818,7 @@ out_html(char *c)
        } else if (output_possible) {
                while (*c) {
                        outbuffer[obp++] = *c;
-                       if (*c == '\n' || obp > HUGE_STR_MAX) {
+                       if (*c == '\n' || obp >= HUGE_STR_MAX) {
                                outbuffer[obp] = '\0';
                                add_links(outbuffer);
                                obp = 0;
diff --git a/trap.c b/trap.c
index 9acd19739f95500dfe8380047c48f944e99ee9bb..778e330d974ae7c6111304ee8eb10a0648bd7a30 100644 (file)
--- a/trap.c
+++ b/trap.c
@@ -1286,7 +1286,9 @@ run_debug_trap (void)
       close_pgrp_pipe ();
       restore_pgrp_pipe (save_pipe);
 #  endif
-      if (pipeline_pgrp > 0 && ((subshell_environment & (SUBSHELL_ASYNC|SUBSHELL_PIPE)) == 0))
+      /* If the trap command gave the terminal to another process group,
+        restore it. XXX - check running_in_background? */
+      if (job_control && pipeline_pgrp > 0 && ((subshell_environment & (SUBSHELL_ASYNC|SUBSHELL_PIPE)) == 0))
        give_terminal_to (pipeline_pgrp, 1);
 
       notify_and_cleanup ();