fix for namerefs referencing an unset array index with nounset enabled; addition to buildconf.h.in for C23 compilers

This commit is contained in:
Chet Ramey
2025-05-30 10:11:03 -04:00
parent 870ad4c92b
commit dbe4256d5e
24 changed files with 2285 additions and 3263 deletions
+42
View File
@@ -1,3 +1,45 @@
This document details the changes between this version, bash-5.3-rc2, and
the previous version, bash-5.3-rc1.
1. Changes to Bash
a. Fixed a problem with invoking the correct programmable completion compspec
if the line contains a quoted command separator before point.
b. Fixed a bug in the `read' builtin that caused it to skip the delimiter if
it appeared in an invalid multibyte character.
c. Fixed a bug with parsing command substitutions that caused a syntax error
to pop too many input sources.
d. Fixed an issue with recursive parsing that caused the parser to reset and
pop all the delimiters off the stack; the caller needs to check for that
possibility.
e. Fixed an issue with interactive input that caused EOF not to exit the
shell if it was read as part of a here-document.
f. Fixed an issue with a backslash-newline appearing after a right paren in
a nested subshell command.
g. Fixed an issue with invalid sequence expressions in brace expansions.
h. Fixed an issue with a nameref variable referencing an unset array element
when the nounset option is enabled.
2. Changes to Readline
a. The history library no longer skips blank lines while it is reading a
multiline history entry from a history file.
3. New Features in Bash
a. The `install-strip' and `strip' Makefile targets now deal with cross-
compiling.
4. New Features in Readline
------------------------------------------------------------------------------
This document details the changes between this version, bash-5.3-rc1, and
the previous version, bash-5.3-beta.
+42
View File
@@ -1,3 +1,45 @@
This document details the changes between this version, bash-5.3-rc2, and
the previous version, bash-5.3-rc1.
1. Changes to Bash
a. Fixed a problem with invoking the correct programmable completion compspec
if the line contains a quoted command separator before point.
b. Fixed a bug in the `read' builtin that caused it to skip the delimiter if
it appeared in an invalid multibyte character.
c. Fixed a bug with parsing command substitutions that caused a syntax error
to pop too many input sources.
d. Fixed an issue with recursive parsing that caused the parser to reset and
pop all the delimiters off the stack; the caller needs to check for that
possibility.
e. Fixed an issue with interactive input that caused EOF not to exit the
shell if it was read as part of a here-document.
f. Fixed an issue with a backslash-newline appearing after a right paren in
a nested subshell command.
g. Fixed an issue with invalid sequence expressions in brace expansions.
h. Fixed an issue with a nameref variable referencing an unset array element
when the nounset option is enabled.
2. Changes to Readline
a. The history library no longer skips blank lines while it is reading a
multiline history entry from a history file.
3. New Features in Bash
a. The `install-strip' and `strip' Makefile targets now deal with cross-
compiling.
4. New Features in Readline
------------------------------------------------------------------------------
This document details the changes between this version, bash-5.3-rc1, and
the previous version, bash-5.3-beta.
+21 -2
View File
@@ -1,4 +1,3 @@
\
12/6/2020
---------
@@ -11248,4 +11247,24 @@ Makefile.in
AM_PROG_INSTALL_STRIP
- install-strip: change to set INSTALL_PROGRAM=${INSTALL_STRIP_PROGRAM}
to avoid hard-coding `-s' in the recipe
All from a report by NR <nroycea+gnu@gmail.com>
All from a report by NR <nroycea+gnu@gmail.com>
5/18
----
subst.c
- param_expand: if we expand a nameref that references an unset array
variable reference, make sure we enforce `nounset', with the usual
exceptions for `@' and `*' subscripts
From a report from Emanuele Torre <torreemanuele6@gmail.com>
5/22
----
buildconf.h.in
- add additional defines for conservative ISO C/POSIX environment
- add HAVE_C_BOOL define in case someone cross-compiles with a C23
compiler
From a report by Bruce Dubbs <bdubbs@linuxfromscratch.org>
builtins/mkbuiltins.c
- include buildconf.h instead of having separate defines when
cross-compiling
+1
View File
@@ -1367,6 +1367,7 @@ tests/nameref21.sub f
tests/nameref22.sub f
tests/nameref23.sub f
tests/nameref24.sub f
tests/nameref25.sub f
tests/nameref.right f
tests/new-exp.tests f
tests/new-exp1.sub f
+3
View File
@@ -146,6 +146,9 @@ uu. If `exit' is run in a trap and not supplied an exit status argument, it
vv. There is a new `fltexpr' builtin to perform floating-point arithmetic
similarly to `let'.
ww. The `install-strip' and `strip' Makefile targets now deal with cross-
compiling.
2. New Features in Readline
a. Output a newline if there is no prompt and readline reads an empty line.
+3
View File
@@ -146,6 +146,9 @@ uu. If `exit' is run in a trap and not supplied an exit status argument, it
vv. There is a new `fltexpr' builtin to perform floating-point arithmetic
similarly to `let'.
ww. The `install-strip' and `strip' Makefile targets now deal with cross-
compiling.
2. New Features in Readline
a. Output a newline if there is no prompt and readline reads an empty line.
+7
View File
@@ -33,6 +33,13 @@
#define HAVE_LOCALE_H 1
#define HAVE_UNISTD_H 1
#define HAVE_STRING_H 1
#define HAVE_STDLIB_H 1
#define HAVE_RENAME
/* defining this implies a C23 environment */
#undef HAVE_C_BOOL
/* Don't assume this; it's from C99; let syntax.h define a replacement */
/* #undef HAVE_ISBLANK */
+1 -5
View File
@@ -23,11 +23,7 @@
# include <config.h>
#else /* CROSS_COMPILING */
/* A conservative set of defines based on POSIX/SUS3/XPG6 */
# define HAVE_UNISTD_H
# define HAVE_STRING_H
# define HAVE_STDLIB_H
# define HAVE_RENAME
# include <buildconf.h>
#endif /* CROSS_COMPILING */
#if defined (HAVE_UNISTD_H)
Vendored
+11 -11
View File
@@ -1,7 +1,7 @@
#! /bin/sh
# From configure.ac for Bash 5.3, version 5.079.
# From configure.ac for Bash 5.3, version 5.080.
# Guess values for system-dependent variables and create Makefiles.
# Generated by GNU Autoconf 2.72 for bash 5.3-rc1.
# Generated by GNU Autoconf 2.72 for bash 5.3-rc2.
#
# Report bugs to <bug-bash@gnu.org>.
#
@@ -605,8 +605,8 @@ MAKEFLAGS=
# Identity of this package.
PACKAGE_NAME='bash'
PACKAGE_TARNAME='bash'
PACKAGE_VERSION='5.3-rc1'
PACKAGE_STRING='bash 5.3-rc1'
PACKAGE_VERSION='5.3-rc2'
PACKAGE_STRING='bash 5.3-rc2'
PACKAGE_BUGREPORT='bug-bash@gnu.org'
PACKAGE_URL=''
@@ -1468,7 +1468,7 @@ if test "$ac_init_help" = "long"; then
# Omit some internal or obsolete options to make the list less imposing.
# This message is too long to be a string in the A/UX 3.1 sh.
cat <<_ACEOF
'configure' configures bash 5.3-rc1 to adapt to many kinds of systems.
'configure' configures bash 5.3-rc2 to adapt to many kinds of systems.
Usage: $0 [OPTION]... [VAR=VALUE]...
@@ -1534,7 +1534,7 @@ fi
if test -n "$ac_init_help"; then
case $ac_init_help in
short | recursive ) echo "Configuration of bash 5.3-rc1:";;
short | recursive ) echo "Configuration of bash 5.3-rc2:";;
esac
cat <<\_ACEOF
@@ -1742,7 +1742,7 @@ fi
test -n "$ac_init_help" && exit $ac_status
if $ac_init_version; then
cat <<\_ACEOF
bash configure 5.3-rc1
bash configure 5.3-rc2
generated by GNU Autoconf 2.72
Copyright (C) 2023 Free Software Foundation, Inc.
@@ -2420,7 +2420,7 @@ cat >config.log <<_ACEOF
This file contains any messages produced by compilers while
running configure, to aid debugging if configure makes a mistake.
It was created by bash $as_me 5.3-rc1, which was
It was created by bash $as_me 5.3-rc2, which was
generated by GNU Autoconf 2.72. Invocation command line was
$ $0$ac_configure_args_raw
@@ -3219,7 +3219,7 @@ ac_config_headers="$ac_config_headers config.h buildconf.h"
BASHVERS=5.3
RELSTATUS=rc1
RELSTATUS=rc2
case "$RELSTATUS" in
alp*|bet*|dev*|rc*|releng*|maint*) DEBUG='-DDEBUG' MALLOC_DEBUG='-DMALLOC_DEBUG' ;;
@@ -23814,7 +23814,7 @@ cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1
# report actual input values of CONFIG_FILES etc. instead of their
# values after options handling.
ac_log="
This file was extended by bash $as_me 5.3-rc1, which was
This file was extended by bash $as_me 5.3-rc2, which was
generated by GNU Autoconf 2.72. Invocation command line was
CONFIG_FILES = $CONFIG_FILES
@@ -23882,7 +23882,7 @@ ac_cs_config_escaped=`printf "%s\n" "$ac_cs_config" | sed "s/^ //; s/'/'\\\\\\\\
cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1
ac_cs_config='$ac_cs_config_escaped'
ac_cs_version="\\
bash config.status 5.3-rc1
bash config.status 5.3-rc2
configured by $0, generated by GNU Autoconf 2.72,
with options \\"\$ac_cs_config\\"
+2 -2
View File
@@ -21,10 +21,10 @@ 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.079])dnl
AC_REVISION([for Bash 5.3, version 5.080])dnl
define(bashvers, 5.3)
define(relstatus, rc1)
define(relstatus, rc2)
AC_INIT([bash], bashvers-relstatus, [bug-bash@gnu.org])
+14 -2
View File
@@ -8596,7 +8596,8 @@ not when the function is executed, because a function definition
is itself a command.
As a consequence, aliases
defined in a function are not available until after that
function is executed. To be safe, always put
function is executed.
To be safe, always put
alias definitions on a separate line, and do not use @code{alias}
in compound commands.
@@ -9586,12 +9587,23 @@ statuses after the @code{wait} builtin returns it.
@end enumerate
There is other @sc{posix} behavior that Bash does not implement by
There is additional @sc{posix} behavior that Bash does not implement by
default even when in @sc{posix} mode.
Specifically:
@enumerate
@item
@sc{posix} requires that word splitting be byte-oriented.
That is, each @emph{byte} in the value of @env{IFS} potentially splits a
word, even if that byte is part of a multibyte character in @env{IFS}
or part of multibyte character in the word.
Bash allows multibyte characters in the value of @env{IFS}, treating
a valid multibyte character as a single delimiter, and will not
split a valid multibyte character even if one of the bytes composing that
character appears in @env{IFS}.
This is @sc{posix} interpretation 1560, further modified by issue 1924.
@item
The @code{fc} builtin checks @code{$EDITOR} as a program to edit history
entries if @code{FCEDIT} is unset, rather than defaulting directly to
+3 -3
View File
@@ -2,10 +2,10 @@
Copyright (C) 1988-2025 Free Software Foundation, Inc.
@end ignore
@set LASTCHANGE Mon Apr 7 16:58:51 EDT 2025
@set LASTCHANGE Sun May 18 13:42:18 EDT 2025
@set EDITION 5.3
@set VERSION 5.3
@set UPDATED 7 April 2025
@set UPDATED-MONTH April 2025
@set UPDATED 18 May 2025
@set UPDATED-MONTH May 2025
BIN
View File
Binary file not shown.
+1317 -1843
View File
File diff suppressed because it is too large Load Diff
BIN
View File
Binary file not shown.
+752 -1143
View File
File diff suppressed because it is too large Load Diff
+19 -2
View File
@@ -10974,9 +10974,26 @@ comsub:
{
chk_atstar (temp, quoted, pflags, quoted_dollar_at_p, contains_dollar_at);
tdesc = parameter_brace_expand_word (temp, SPECIAL_VAR (temp, 0), quoted, pflags, 0);
free (temp1);
if (tdesc == &expand_wdesc_error || tdesc == &expand_wdesc_fatal)
return (tdesc);
{
free (temp1);
return (tdesc);
}
/* check for a nameref pointing to an unset array reference
where the subscript is not `@' or `*' and enforce nounset
if enabled. */
if ((tdesc == 0 || tdesc->word == 0) && unbound_vars_is_error)
{
char *sub;
sub = mbschr (temp, LBRACK);
if (DOLLAR_AT_STAR (sub[1]) == 0 || sub[2] != RBRACK)
{
temp = (char *)NULL;
goto unbound_variable;
}
}
free (temp1);
ret = tdesc;
goto return0;
}
Regular → Executable
View File
-247
View File
@@ -1,247 +0,0 @@
#!/bin/sh
#
# install - install a program, script, or datafile
# This comes from X11R5.
#
# $XConsortium: install.sh,v 1.2 89/12/18 14:47:22 jim Exp $
#
# Copyright 1991 by the Massachusetts Institute of Technology
#
# Permission to use, copy, modify, distribute, and sell this software and its
# documentation for any purpose is hereby granted without fee, provided that
# the above copyright notice appear in all copies and that both that
# copyright notice and this permission notice appear in supporting
# documentation, and that the name of M.I.T. not be used in advertising or
# publicity pertaining to distribution of the software without specific,
# written prior permission. M.I.T. makes no representations about the
# suitability of this software for any purpose. It is provided "as is"
# without express or implied warranty.
#
# This script is compatible with the BSD install script, but was written
# from scratch.
#
# set DOITPROG to echo to test this script
# Don't use :- since 4.3BSD and earlier shells don't like it.
doit="${DOITPROG-}"
# put in absolute paths if you don't have them in your path; or use env. vars.
mvprog="${MVPROG-mv}"
cpprog="${CPPROG-cp}"
chmodprog="${CHMODPROG-chmod}"
chownprog="${CHOWNPROG-chown}"
chgrpprog="${CHGRPPROG-chgrp}"
stripprog="${STRIPPROG-strip}"
rmprog="${RMPROG-rm}"
mkdirprog="${MKDIRPROG-mkdir}"
tranformbasename=""
transform_arg=""
instcmd="$mvprog"
chmodcmd="$chmodprog 0755"
chowncmd=""
chgrpcmd=""
stripcmd=""
rmcmd="$rmprog -f"
mvcmd="$mvprog"
src=""
dst=""
dir_arg=""
while [ x"$1" != x ]; do
case $1 in
-c) instcmd="$cpprog"
shift
continue;;
-d) dir_arg=true
shift
continue;;
-m) chmodcmd="$chmodprog $2"
shift
shift
continue;;
-o) chowncmd="$chownprog $2"
shift
shift
continue;;
-g) chgrpcmd="$chgrpprog $2"
shift
shift
continue;;
-s) stripcmd="$stripprog"
shift
continue;;
-t=*) transformarg=`echo $1 | sed 's/-t=//'`
shift
continue;;
-b=*) transformbasename=`echo $1 | sed 's/-b=//'`
shift
continue;;
*) if [ x"$src" = x ]
then
src=$1
else
# this colon is to work around a 386BSD /bin/sh bug
:
dst=$1
fi
shift
continue;;
esac
done
if [ x"$src" = x ]
then
echo "install: no input file specified"
exit 1
else
true
fi
if [ x"$dir_arg" != x ]; then
dst=$src
src=""
if [ -d $dst ]; then
instcmd=:
else
instcmd=mkdir
fi
else
# Waiting for this to be detected by the "$instcmd $src $dsttmp" command
# might cause directories to be created, which would be especially bad
# if $src (and thus $dsttmp) contains '*'.
if [ -f $src -o -d $src ]
then
true
else
echo "install: $src does not exist"
exit 1
fi
if [ x"$dst" = x ]
then
echo "install: no destination specified"
exit 1
else
true
fi
# If destination is a directory, append the input filename; if your system
# does not like double slashes in filenames, you may need to add some logic
if [ -d $dst ]
then
dst="$dst"/`basename $src`
else
true
fi
fi
## this sed command emulates the dirname command
dstdir=`echo $dst | sed -e 's,[^/]*$,,;s,/$,,;s,^$,.,'`
# Make sure that the destination directory exists.
# this part is taken from Noah Friedman's mkinstalldirs script
# Skip lots of stat calls in the usual case.
if [ ! -d "$dstdir" ]; then
defaultIFS='
'
IFS="${IFS-${defaultIFS}}"
oIFS="${IFS}"
# Some sh's can't handle IFS=/ for some reason.
IFS='%'
set - `echo ${dstdir} | sed -e 's@/@%@g' -e 's@^%@/@'`
IFS="${oIFS}"
pathcomp=''
while [ $# -ne 0 ] ; do
pathcomp="${pathcomp}${1}"
shift
if [ ! -d "${pathcomp}" ] ;
then
$mkdirprog "${pathcomp}"
else
true
fi
pathcomp="${pathcomp}/"
done
fi
if [ x"$dir_arg" != x ]
then
$doit $instcmd $dst &&
if [ x"$chowncmd" != x ]; then $doit $chowncmd $dst; else true ; fi &&
if [ x"$chgrpcmd" != x ]; then $doit $chgrpcmd $dst; else true ; fi &&
if [ x"$stripcmd" != x ]; then $doit $stripcmd $dst; else true ; fi &&
if [ x"$chmodcmd" != x ]; then $doit $chmodcmd $dst; else true ; fi
else
# If we're going to rename the final executable, determine the name now.
if [ x"$transformarg" = x ]
then
dstfile=`basename $dst`
else
dstfile=`basename $dst $transformbasename |
sed $transformarg`$transformbasename
fi
# don't allow the sed command to completely eliminate the filename
if [ x"$dstfile" = x ]
then
dstfile=`basename $dst`
else
true
fi
# Make a temp file name in the proper directory.
dsttmp=$dstdir/#inst.$$#
# Move or copy the file name to the temp name
$doit $instcmd $src $dsttmp &&
trap "rm -f ${dsttmp}" 0 &&
# and set any options; do chmod last to preserve setuid bits
# If any of these fail, we abort the whole thing. If we want to
# ignore errors from any of these, just make sure not to ignore
# errors from the above "$doit $instcmd $src $dsttmp" command.
if [ x"$chowncmd" != x ]; then $doit $chowncmd $dsttmp; else true;fi &&
if [ x"$chgrpcmd" != x ]; then $doit $chgrpcmd $dsttmp; else true;fi &&
if [ x"$stripcmd" != x ]; then $doit $stripcmd $dsttmp; else true;fi &&
if [ x"$chmodcmd" != x ]; then $doit $chmodcmd $dsttmp; else true;fi &&
# Now rename the file to the real destination.
$doit $rmcmd -f $dstdir/$dstfile &&
$doit $mvcmd $dsttmp $dstdir/$dstfile
fi &&
exit 0
+3
View File
@@ -78,6 +78,9 @@ a ../a.cfg
a.. /a.cfg
a..b /a.cfg
a b../a.cfg
1..4 5..8
1..4 8
1 5..8
{abcde.f}
X{..a}Z
0{1..}2
+4
View File
@@ -147,6 +147,10 @@ echo {a..,/a.cfg}
echo {a..b,/a.cfg}
echo {a,b../a.cfg}
echo {1..4,5..8}
echo {1..4,8}
echo {1,5..8}
# these are all invalid brace expansions
echo {abcde.f}
+15 -3
View File
@@ -535,16 +535,16 @@ declare -ai a=([0]="5")
declare -ai a=([0]="6")
declare -ai a=([0]="42")
declare -ai a=([0]="1")
./nameref23.sub: line 16: declare: b: not found
./nameref23.sub: line 29: declare: b: not found
declare -ai a=([0]="1")
declare -- b="1"
declare -ai a=([0]="1")
declare -- b="11"
declare -ai a=([0]="1")
declare -- b="110"
./nameref23.sub: line 26: declare: `1': invalid variable name for name reference
./nameref23.sub: line 39: declare: `1': invalid variable name for name reference
declare -ai a=([0]="1")
./nameref23.sub: line 28: declare: b: not found
./nameref23.sub: line 41: declare: b: not found
declare -ai a=([0]="4")
declare -in b="a[0]"
declare -ai a=([0]="6")
@@ -574,3 +574,15 @@ declare -ai a=([0]="0" [1]="16")
3
3
5
/usr/local/build/bash/bash-current/bash: line 1: a[k]: unbound variable
ok 1
/usr/local/build/bash/bash-current/bash: line 1: r0: unbound variable
ok 2
/usr/local/build/bash/bash-current/bash: line 1: r: unbound variable
ok 3
/usr/local/build/bash/bash-current/bash: line 1: k: unbound variable
ok 4
ok 5
ok 6
ok 7
ok 8
+13
View File
@@ -1,3 +1,16 @@
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
declare -ai a
a[0]=4
declare -n b='a[0]'
+12
View File
@@ -0,0 +1,12 @@
# issues with nounset and references to nameref variables whose value
# contains an unset variable
$THIS_SH -uc 'a=() k=; "${a[k]}"' || echo ok 1
$THIS_SH -uc 'declare -n r0=b ; : "$r0"' || echo ok 2
$THIS_SH -uc 'a=() k=; declare -n r='a[k]' ; : "$r"' || echo ok 3
$THIS_SH -uc 'declare -n r='a[k]' ; : "$r"' || echo ok 4
$THIS_SH -uc 'a=() k=; declare -n r='a[@]' ; : "$r"' && echo ok 5
$THIS_SH -uc 'declare -n r='a[@]' ; : "$r"' && echo ok 6
$THIS_SH -uc 'a=() k=; declare -n r='a[*]' ; : "$r"' && echo ok 7
$THIS_SH -uc 'declare -n r='a[*]' ; : "$r"' && echo ok 8