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

This commit is contained in:
Chet Ramey
2024-05-20 10:48:44 -04:00
parent b3d8c8a4e7
commit dbd27e54cc
18 changed files with 120 additions and 51 deletions
+35 -1
View 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>
+3
View 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
+12 -3
View File
@@ -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
+4 -2
View 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);
Vendored
+1 -24
View File
@@ -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"
+1 -4
View 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
+1 -1
View 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.
+1 -1
View 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,
+3 -1
View 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>
+2
View 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>
+3 -3
View 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 (;;) {
+7 -3
View File
@@ -20,7 +20,13 @@
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"
+14 -3
View File
@@ -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)
{
+2 -2
View 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. */
+6 -2
View File
@@ -18,9 +18,13 @@
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>
+6
View 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
+12
View 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
+7 -1
View File
@@ -18,7 +18,13 @@
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>