]> git.ipfire.org Git - thirdparty/bash.git/commitdiff
fix to backslash quoting of glob pattern characters; allow newly-loaded compspecs...
authorChet Ramey <chet.ramey@case.edu>
Mon, 20 May 2024 14:48:44 +0000 (10:48 -0400)
committerChet Ramey <chet.ramey@case.edu>
Mon, 20 May 2024 14:48:44 +0000 (10:48 -0400)
18 files changed:
CWRU/CWRU.chlog
Makefile.in
buildconf.h.in
builtins/source.def
configure
configure.ac
doc/bash.1
doc/bashref.texi
examples/loadables/asort.c
examples/loadables/cat.c
lib/sh/inet_aton.c
mksyntax.c
pathexp.c
pcomplete.c
support/bashversion.c
tests/new-exp.right
tests/new-exp.tests
version.c

index c7e7f024d9c837112331cd6a6f9a9ac05bb3c845..0d20018a44b56d4f1c7e169773194f37112d4ba1 100644 (file)
@@ -9419,4 +9419,38 @@ doc/bash.1,lib/readline/doc/readline.3,lib/readline/doc/rltech.texi
 
 configure
        - make sure to note in CHANGES that configure now supports
-         --enable-year-2038 for large time_t
+         --enable-year2038 for large time_t
+
+                                  5/14
+                                  ----
+pathexp.c
+       - glob_quote_char: new function, identify characters that should have
+         backslashes preserved when quoting a glob pattern. Currently has
+         all the glob_char_p characters plus `%' and `#' for pattern
+         substitution and removal.
+         Fixes issue reported by Andreas Schwab <schwab@suse.de>
+
+                                  5/16
+                                  ----
+pcomplete.c
+       - programmable_completions: change to allow a newly-loaded compspec
+         (after a completion function returns 124) to be used in more cases
+         From a patch from Grisha Levit <grishalevit@gmail.com>
+
+mksyntax.c,version.c,support/bashversion.c
+       - include config.h if CROSS_COMPILING is not defined, assuming that
+         the build host and target host are the same
+
+buildconf.h.in
+       - if cross-compiling, define _POSIX_C_SOURCE and _XOPEN_SOURCE to
+         get the C90/1003.1-1992 compilation environment we assume
+         From a report from Grisha Levit <grishalevit@gmail.com>
+
+                                  5/17
+                                  ----
+pathexp.c
+       - globsort_sizecmp,globsort_blockscmp: replace subtraction with a
+         generic transitive comparison function to avoid problems with
+         integer underflow
+         From a report from Grisha Levit <grishalevit@gmail.com>
+
index 51c55bf9bca5860a7b7c3f5e74726c2f002a7baa..848f8e023636d8f252e9ef48b5067d9752e6ecfc 100644 (file)
@@ -836,6 +836,9 @@ pathnames.h:                Makefile $(srcdir)/pathnames.h.in
        fi
        @${RM} pathnames.tmp
 
+buildconf.h:   $(srcdir)/buildconf.h.in
+       CONFIG_FILES= CONFIG_HEADERS=buildconf.h $(SHELL) ./config.status
+
 $(SDIR)/bashbug.sh: $(SDIR)/bashbug.sh.in
        CONFIG_FILES=$(SDIR)/bashbug.sh CONFIG_HEADERS= $(SHELL) ./config.status
 
index 38976a51c26edaf165841d61467af3b73fe82ab6..6d9b77dd32e5fc2179bd129d8182bf5c2a9190b6 100644 (file)
 #if !defined (BUILDCONF_H_)
 #define BUILDCONF_H_
 
-#undef HAVE_LOCALE_H
+/* assume C90/POSIX-1992 compilation environment if cross-compiling */
 
-#undef HAVE_UNISTD_H
+/* pacify glibc */
+#ifndef _POSIX_C_SOURCE
+#  define _POSIX_C_SOURCE 2
+#  define _XOPEN_SOURCE 500
+#endif
 
-#undef HAVE_ISBLANK
+#define HAVE_LOCALE_H 1
+
+#define HAVE_UNISTD_H 1
+
+/* Don't assume this; it's from C99; let syntax.h define a replacement */
+/* #undef HAVE_ISBLANK */
 
 #undef PROCESS_SUBSTITUTION
 
index 51dddec6d8b3bb37c566222b44ad07859817b0d8..1c2de0ab4711cb9921f32ec0bd6d346a0180e1ab 100644 (file)
@@ -115,7 +115,7 @@ uw_maybe_pop_dollar_vars (void *ignore)
 int
 source_builtin (WORD_LIST *list)
 {
-  int result;
+  int result, search_cwd;
   char *filename, *debug_trap, *x;
 
   if (no_options (list))
@@ -137,6 +137,8 @@ source_builtin (WORD_LIST *list)
     }
 #endif
 
+  search_cwd = source_searches_cwd;
+
   filename = (char *)NULL;
   /* XXX -- should this be absolute_pathname? */
   if (posixly_correct && strchr (list->word->word, '/'))
@@ -159,7 +161,7 @@ source_builtin (WORD_LIST *list)
     }
   if (filename == 0)
     {
-      if (source_searches_cwd == 0)
+      if (search_cwd == 0)
        {
          x = printable_filename (list->word->word, 0);
          builtin_error (_("%s: file not found"), x);
index 388c67c69afbca01087c9e2e473acdae83dc4c0f..49d85cf3ae428a4eacce9e982ec89a89b4e68741 100755 (executable)
--- a/configure
+++ b/configure
@@ -1,5 +1,5 @@
 #! /bin/sh
-# From configure.ac for Bash 5.3, version 5.063.
+# From configure.ac for Bash 5.3, version 5.064.
 # Guess values for system-dependent variables and create Makefiles.
 # Generated by GNU Autoconf 2.72 for bash 5.3-alpha.
 #
@@ -18564,29 +18564,6 @@ printf "%s\n" "#define SIZEOF_LONG_LONG $ac_cv_sizeof_long_long" >>confdefs.h
 
 
 
-ac_fn_c_check_type "$LINENO" "u_int" "ac_cv_type_u_int" "$ac_includes_default"
-if test "x$ac_cv_type_u_int" = xyes
-then :
-
-else case e in #(
-  e)
-printf "%s\n" "#define u_int unsigned int" >>confdefs.h
- ;;
-esac
-fi
-
-ac_fn_c_check_type "$LINENO" "u_long" "ac_cv_type_u_long" "$ac_includes_default"
-if test "x$ac_cv_type_u_long" = xyes
-then :
-
-else case e in #(
-  e)
-printf "%s\n" "#define u_long unsigned long" >>confdefs.h
- ;;
-esac
-fi
-
-
 
 if test "$ac_cv_sizeof_short" = 2; then
   ac_fn_c_check_type "$LINENO" "bits16_t" "ac_cv_type_bits16_t" "$ac_includes_default"
index 20ba3d34c6dc9a2528658adcd8882529cf5579c0..982ff5e13425699c320f62fe8da39f16cd652e32 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.063])dnl
+AC_REVISION([for Bash 5.3, version 5.064])dnl
 
 define(bashvers, 5.3)
 define(relstatus, alpha)
@@ -1014,9 +1014,6 @@ AC_CHECK_SIZEOF(size_t, 4)
 AC_CHECK_SIZEOF(double, 8)
 AC_CHECK_SIZEOF([long long], 8)
 
-AC_CHECK_TYPE(u_int, [unsigned int])
-AC_CHECK_TYPE(u_long, [unsigned long])
-
 BASH_TYPE_BITS16_T
 BASH_TYPE_U_BITS16_T
 BASH_TYPE_BITS32_T
index f60d090e8b1f1ed76e43f4373c83bedd3b5bf3f2..bf8c6198f89b6050ffb2d1506d460907d3dc8bf7 100644 (file)
@@ -2326,7 +2326,7 @@ inode change time, and number of blocks, respectively.
 For example, a value of \fI\-mtime\fP sorts the results in descending
 order by modification time (newest first).
 A sort specifier of \fInosort\fP disables sorting completely; the results
-are returned in the order they are read from the file system,.
+are returned in the order they are read from the file system.
 If the sort specifier is missing, it defaults to \fIname\fP,
 so a value of \fI+\fP is equivalent to the null string,
 and a value of \fI-\fP sorts by name in descending order.
index 44bf379cd002ead2a184531745894c3db888a88f..70f3e206605e5c8111f7d8c2eb142ed19c95f376 100644 (file)
@@ -6694,7 +6694,7 @@ For example, a value of @code{-mtime} sorts the results in descending
 order by modification time (newest first).
 
 A sort specifier of @samp{nosort} disables sorting completely; the results
-are returned in the order they are read from the file system,.
+are returned in the order they are read from the file system.
 
 If the sort specifier is missing, it defaults to @var{name},
 so a value of @samp{+} is equivalent to the null string,
index 10003677674fe8ed2147a4e6ae37069519b94e9c..00a343642524e34aafc3534686a13a932ae22152 100644 (file)
@@ -1,5 +1,5 @@
 /*
-   Copyright (C) 2020,2022,2023 Free Software Foundation, Inc.
+   Copyright (C) 2020,2022-2024 Free Software Foundation, Inc.
 
    Bash is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
@@ -16,6 +16,8 @@
 */
 /* Contributed by Geir Hauge <geir.hauge@gmail.com> */
 
+#include <config.h>
+
 #include <stdlib.h>
 #include <string.h>
 #include <inttypes.h>
index b476a0ee52488ca0bb37ba6b155456fb3ed1f706..5ce2c9a48706ddb5c68c92415da0ef3d059ceb8e 100644 (file)
@@ -22,6 +22,8 @@
    along with Bash.  If not, see <http://www.gnu.org/licenses/>.
 */
 
+#include <config.h>
+
 #include <fcntl.h>
 #include <errno.h>
 
index 3715850c919ed2d7bfe76862d28004b81b28a289..2e1975f3e960090c5e7333832cef813a4fad7bae 100644 (file)
@@ -93,7 +93,7 @@ static char rcsid[] = "$Id: inet_addr.c,v 1.5 1996/08/14 03:48:37 drepper Exp $"
  * Ascii internet address interpretation routine.
  * The value returned is in network order.
  */
-u_long
+in_addr_t
 inet_addr(const char *cp)
 {
        struct in_addr val;
@@ -117,8 +117,8 @@ inet_aton(const char *cp, struct in_addr *addr)
        register u_bits32_t val;
        register int base, n;
        register unsigned char c;
-       u_int parts[4];
-       register u_int *pp = parts;
+       unsigned int parts[4];
+       register unsigned int *pp = parts;
 
        c = *cp;
        for (;;) {
index 0020f0cb18c47bd454152fcd583533626286cf5e..5a64c8f57a5a9868a12bdc9614d1b81b95ecdbff 100644 (file)
    along with Bash.  If not, see <http://www.gnu.org/licenses/>.
 */
 
-/* assume C90 compilation environment */
+/* assume C90/POSIX-1992 compilation environment if cross-compiling */
+
+#ifndef CROSS_COMPILING
+#  include <config.h>
+#else
+#  include <buildconf.h>
+#endif
 
 #include <stdio.h>
 #include <string.h>
@@ -28,8 +34,6 @@
 #include <errno.h>
 #include <unistd.h>
 
-#include <buildconf.h>
-
 #include "chartypes.h"
 #include "syntax.h"
 
index f62efafb6c5cf2487b26d90eff06a0be54a0e847..d60ff66d9fcfe67cdc2cb32603b2f00f25a9c0f1 100644 (file)
--- a/pathexp.c
+++ b/pathexp.c
@@ -189,6 +189,12 @@ glob_char_p (const char *s)
   return 0;
 }
 
+static inline int
+glob_quote_char (const char *s)
+{
+  return (glob_char_p (s) || (*s == '%') || (*s == '#'));
+}
+
 /* PATHNAME can contain characters prefixed by CTLESC; this indicates
    that the character is to be quoted.  We quote it here in the style
    that the glob library recognizes.  If flags includes QGLOB_CVTNULL,
@@ -253,7 +259,7 @@ convert_to_backslash:
 
          /* We don't have to backslash-quote non-special BRE characters if
             we're quoting a glob pattern. */
-         if (cc != CTLESC && (qflags & QGLOB_REGEXP) == 0 && glob_char_p (pathname+i+1) == 0)
+         if (cc != CTLESC && (qflags & QGLOB_REGEXP) == 0 && glob_quote_char (pathname+i+1) == 0)
            continue;
 
          /* If we're in a multibyte locale, don't bother quoting multibyte
@@ -744,10 +750,13 @@ globsort_namecmp (char **s1, char **s2)
   return ((glob_sorttype < SORT_REVERSE) ? strvec_posixcmp (s1, s2) : strvec_posixcmp (s2, s1));
 }
 
+/* Generic transitive comparison of two numeric values for qsort */
+#define GENCMP(a,b) (a < b ? -1 : (a > b ? 1 : 0))
+
 static int
 globsort_sizecmp (struct globsort_t *g1, struct globsort_t *g2)
 {
-  return ((glob_sorttype < SORT_REVERSE) ? g1->st.size - g2->st.size : g2->st.size - g1->st.size);
+  return ((glob_sorttype < SORT_REVERSE) ? GENCMP(g1->st.size, g2->st.size) : GENCMP(g2->st.size, g1->st.size));
 }
 
 static int
@@ -779,9 +788,11 @@ globsort_timecmp (struct globsort_t *g1, struct globsort_t *g2)
 static int
 globsort_blockscmp (struct globsort_t *g1, struct globsort_t *g2)
 {
-  return ((glob_sorttype < SORT_REVERSE) ? g1->st.blocks - g2->st.blocks : g2->st.blocks - g1->st.blocks);
+  return (glob_sorttype < SORT_REVERSE ? GENCMP(g1->st.blocks, g2->st.blocks) : GENCMP(g2->st.blocks, g1->st.blocks));
 }
 
+#undef GENCMP
+
 static struct globsort_t *
 globsort_buildarray (char **array, size_t len)
 {
index aa6a0440b20c65fe21bc9d6d046f24c80a384060..e00387795bb3333da74600b401ef9889db307e9c 100644 (file)
@@ -1564,7 +1564,7 @@ programmable_completions (const char *cmd, const char *word,
 #endif
 
   lastcs = 0;
-  found = count = 0;
+  count = 0;
 
   pcomp_line = rl_line_buffer;
   pcomp_ind = rl_point;
@@ -1574,7 +1574,7 @@ programmable_completions (const char *cmd, const char *word,
 
   do
     {
-      retry = 0;
+      retry = found = 0;
 
       /* We look at the basename of CMD if the full command does not have
         an associated COMPSPEC. */
index 6f9459eb8e3a6e1aea446ab7441efbdca9d15135..5c2d80190ef65b267dcf7ad91f26eea4d7d09f81 100644 (file)
    along with Bash.  If not, see <http://www.gnu.org/licenses/>.
 */
 
-#include <buildconf.h>
+/* assume C90/POSIX-1992 compilation environment if cross-compiling */
 
-/* assume C90 compilation environment */
+#ifndef CROSS_COMPILING
+#  include <config.h>
+#else
+#  include <buildconf.h>
+#endif
 
 #include <stdio.h>
 #include <string.h>
index c926871d980ac0357e2eda0e929507458be67826..d412e8ac2da56d7853ca967fae91166f4b22c644 100644 (file)
@@ -801,4 +801,10 @@ otwone
 argv[1] = </>
 argv[1] = </>
 
+1/##2/%3
+1/##2/##3
+1##2/%3
+1/%%2/#3
+1/%%2/%%3
+1%%2/#3
 ./new-exp.tests: line 1: ABXD: parameter unset
index cabaf7b0f82ab1a49e2fed3f2a994c9831b3cef2..43c222096680abd311ec8a9d3810702ea77f45f8 100644 (file)
@@ -655,5 +655,17 @@ patfunc foo
 # caused core dumps because of bad bracket expression parsing in bash-5.0
 eval : $'${x/#[0\xef\xbf\xbd\\Z[:]]}'
 
+a=1/%2/%3
+echo "${a/\%/##}"
+echo "${a//\%/##}"
+echo "${a/\/%/##}"
+
+b=1/#2/#3
+echo "${b/\#/%%}"
+echo "${b//\#/%%}"
+echo "${b/\/#/%%}"
+
+unset a b
+
 expect $0: 'ABXD: parameter unset'
 ${THIS_SH} -c 'recho ${ABXD:?"parameter unset"}' $0
index 19072719d6293525b7854ccc3b9d637facf78e5c..549e74aed73dd31dd3a5ecdccecce346ebf9901f 100644 (file)
--- a/version.c
+++ b/version.c
    along with Bash.  If not, see <http://www.gnu.org/licenses/>.
 */
 
-#include <buildconf.h>
+/* assume C90/POSIX-1992 compilation environment if cross-compiling */
+
+#ifndef CROSS_COMPILING
+#  include <config.h>
+#else
+#  include <buildconf.h>
+#endif
 
 #include <stdio.h>