From: Chet Ramey Date: Mon, 20 May 2024 14:48:44 +0000 (-0400) Subject: fix to backslash quoting of glob pattern characters; allow newly-loaded compspecs... X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=dbd27e54cc741b116d5ce0e731b778c4f014a74e;p=thirdparty%2Fbash.git fix to backslash quoting of glob pattern characters; allow newly-loaded compspecs to be used in more cases; fixes to the cross-compiling environment; avoid potential overflow in GLOBSORT processing --- diff --git a/CWRU/CWRU.chlog b/CWRU/CWRU.chlog index c7e7f024..0d20018a 100644 --- a/CWRU/CWRU.chlog +++ b/CWRU/CWRU.chlog @@ -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 + + 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 + +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 + + 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 + diff --git a/Makefile.in b/Makefile.in index 51c55bf9..848f8e02 100644 --- a/Makefile.in +++ b/Makefile.in @@ -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 diff --git a/buildconf.h.in b/buildconf.h.in index 38976a51..6d9b77dd 100644 --- a/buildconf.h.in +++ b/buildconf.h.in @@ -22,11 +22,20 @@ #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 diff --git a/builtins/source.def b/builtins/source.def index 51dddec6..1c2de0ab 100644 --- a/builtins/source.def +++ b/builtins/source.def @@ -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); diff --git a/configure b/configure index 388c67c6..49d85cf3 100755 --- 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" diff --git a/configure.ac b/configure.ac index 20ba3d34..982ff5e1 100644 --- a/configure.ac +++ b/configure.ac @@ -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 . -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 diff --git a/doc/bash.1 b/doc/bash.1 index f60d090e..bf8c6198 100644 --- a/doc/bash.1 +++ b/doc/bash.1 @@ -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. diff --git a/doc/bashref.texi b/doc/bashref.texi index 44bf379c..70f3e206 100644 --- a/doc/bashref.texi +++ b/doc/bashref.texi @@ -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, diff --git a/examples/loadables/asort.c b/examples/loadables/asort.c index 10003677..00a34364 100644 --- a/examples/loadables/asort.c +++ b/examples/loadables/asort.c @@ -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 */ +#include + #include #include #include diff --git a/examples/loadables/cat.c b/examples/loadables/cat.c index b476a0ee..5ce2c9a4 100644 --- a/examples/loadables/cat.c +++ b/examples/loadables/cat.c @@ -22,6 +22,8 @@ along with Bash. If not, see . */ +#include + #include #include diff --git a/lib/sh/inet_aton.c b/lib/sh/inet_aton.c index 3715850c..2e1975f3 100644 --- a/lib/sh/inet_aton.c +++ b/lib/sh/inet_aton.c @@ -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 (;;) { diff --git a/mksyntax.c b/mksyntax.c index 0020f0cb..5a64c8f5 100644 --- a/mksyntax.c +++ b/mksyntax.c @@ -20,7 +20,13 @@ along with Bash. If not, see . */ -/* assume C90 compilation environment */ +/* assume C90/POSIX-1992 compilation environment if cross-compiling */ + +#ifndef CROSS_COMPILING +# include +#else +# include +#endif #include #include @@ -28,8 +34,6 @@ #include #include -#include - #include "chartypes.h" #include "syntax.h" diff --git a/pathexp.c b/pathexp.c index f62efafb..d60ff66d 100644 --- 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) { diff --git a/pcomplete.c b/pcomplete.c index aa6a0440..e0038779 100644 --- a/pcomplete.c +++ b/pcomplete.c @@ -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. */ diff --git a/support/bashversion.c b/support/bashversion.c index 6f9459eb..5c2d8019 100644 --- a/support/bashversion.c +++ b/support/bashversion.c @@ -18,9 +18,13 @@ along with Bash. If not, see . */ -#include +/* assume C90/POSIX-1992 compilation environment if cross-compiling */ -/* assume C90 compilation environment */ +#ifndef CROSS_COMPILING +# include +#else +# include +#endif #include #include diff --git a/tests/new-exp.right b/tests/new-exp.right index c926871d..d412e8ac 100644 --- a/tests/new-exp.right +++ b/tests/new-exp.right @@ -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 diff --git a/tests/new-exp.tests b/tests/new-exp.tests index cabaf7b0..43c22209 100644 --- a/tests/new-exp.tests +++ b/tests/new-exp.tests @@ -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 diff --git a/version.c b/version.c index 19072719..549e74ae 100644 --- a/version.c +++ b/version.c @@ -18,7 +18,13 @@ along with Bash. If not, see . */ -#include +/* assume C90/POSIX-1992 compilation environment if cross-compiling */ + +#ifndef CROSS_COMPILING +# include +#else +# include +#endif #include