commit bash-20180928 snapshot

This commit is contained in:
Chet Ramey
2018-10-01 16:19:21 -04:00
parent 3d31a311da
commit 5fab8dbf24
22 changed files with 1116 additions and 1395 deletions
+49
View File
@@ -4443,3 +4443,52 @@ arrayfunc.c
`normal' keys for associative arrays and evaluate to 0 for indexed
arrays. More of fix for report from Grisha Levit
<grishalevit@gmail.com>
9/24
----
bashline.c
- restore_tilde: if the expanded length (xl) is longer than vl
we end up requesting a negative amount of memory (an extremely
large unsigned number). Just punt and return val in this case.
Fuzzing bug reported by Eduardo Bustamante <dualbus@gmail.com>
- restore_tilde: make sure we return what the user typed if tilde
expansion fails
9/29
----
builtins/shopt.def
- uncomment `localvar_unset' option definition
doc/{bash.1,bashref.texi}
- document `localvar_unset' shell option
arrayfunc.c
- valid_array_reference: if we are parsing a subscript for an existing
associative array, the `assoc_expand_once' option is set, and the
VA_ONEWORD flag is set in FLAGS (meaning there should be nothing
following the closing `]'), don't call skipsubscript to find the
closing `]', use one that is at the end of the word. Part of fix for
issue reported by Grisha Levit <grishalevit@gmail.com>
builtins/{printf,set}.def
- pass VA_ONEWORD as part of flags value everywhere valid_array_reference
is used
config-top.h
- CHECKWINSIZE_DEFAULT: now 1, so check_window_size is on by default
- HISTEXPAND_DEFAULT: new define, allows builder to enable or disable
history expansion by default at build time
doc/{bash.1,bashref.texi}
- checkwinsize: document new default value
bashhist.h
- HISTEXPAND_DEFAULT: don't define if it's already defined. Strict
POSIX mode continues to default to off
9/30
----
lib/readline/input.c
- win32_isatty: win32-specific changes from GDB. Patch submitted by
Tom Tromey <tom@tromey.com>, originally from Eli Zaretskii
<eliz@gnu.org>
+1
View File
@@ -870,6 +870,7 @@ tests/array23.sub f
tests/array24.sub f
tests/array25.sub f
tests/array26.sub f
tests/array27.sub f
tests/array-at-star f
tests/array2.right f
tests/assoc.tests f
+14 -7
View File
@@ -890,31 +890,38 @@ print_assoc_assignment (var, quoted)
/***********************************************************************/
/* Return 1 if NAME is a properly-formed array reference v[sub]. */
/* We need to reserve 1 for FLAGS, which we pass to skipsubscript. */
int
valid_array_reference (name, flags)
const char *name;
int flags;
{
char *t;
int r, len;
int r, len, isassoc;
SHELL_VAR *entry;
t = mbschr (name, '['); /* ] */
if (t)
{
*t = '\0';
r = legal_identifier (name);
isassoc = (entry = find_variable (name)) && assoc_p (entry);
*t = '[';
if (r == 0)
return 0;
/* Check for a properly-terminated non-null subscript. */
len = skipsubscript (t, 0, flags);
if (t[len] != ']' || len == 1)
return 0;
if (t[len+1] != '\0')
if (isassoc && ((flags & (VA_NOEXPAND|VA_ONEWORD)) == (VA_NOEXPAND|VA_ONEWORD)))
len = strlen (t) - 1;
else
/* Check for a properly-terminated non-null subscript. */
len = skipsubscript (t, 0, flags&VA_NOEXPAND); /* VA_NOEXPAND must be 1 */
if (t[len] != ']' || len == 1 || t[len+1] != '\0')
return 0;
#if 0
/* Could check and allow subscripts consisting only of whitespace for
existing associative arrays. */
existing associative arrays, using isassoc */
for (r = 1; r < len; r++)
if (whitespace (t[r]) == 0)
return 1;
+6
View File
@@ -40,6 +40,10 @@ extern int array_expand_once;
#define AV_ASSIGNRHS 0x010 /* no splitting, special case ${a[@]} */
#define AV_NOEXPAND 0x020 /* don't run assoc subscripts through word expansion */
/* Flags for valid_array_reference. Value 1 is reserved for skipsubscript() */
#define VA_NOEXPAND 0x001
#define VA_ONEWORD 0x002
extern SHELL_VAR *convert_var_to_array __P((SHELL_VAR *));
extern SHELL_VAR *convert_var_to_assoc __P((SHELL_VAR *));
@@ -83,6 +87,8 @@ extern SHELL_VAR *array_variable_part __P((const char *, int, char **, int *));
#define AV_USEIND 0
#define AV_ASSIGNRHS 0
#define VA_ONEWORD 0
#endif
#endif /* !_ARRAYFUNC_H_ */
+4 -1
View File
@@ -31,9 +31,12 @@
#define HC_IGNBOTH (HC_IGNSPACE|HC_IGNDUPS)
#if defined (STRICT_POSIX)
# undef HISTEXPAND_DEFAULT
# define HISTEXPAND_DEFAULT 0
#else
# define HISTEXPAND_DEFAULT 1
# if !defined (HISTEXPAND_DEFAULT)
# define HISTEXPAND_DEFAULT 1
# endif /* !HISTEXPAND_DEFAULT */
#endif
extern int remember_on_history;
+22 -1
View File
@@ -2988,7 +2988,7 @@ restore_tilde (val, directory_part)
char *val, *directory_part;
{
int l, vl, dl2, xl;
char *dh2, *expdir, *ret;
char *dh2, *expdir, *ret, *v;
vl = strlen (val);
@@ -3000,6 +3000,22 @@ restore_tilde (val, directory_part)
expdir = bash_tilde_expand (directory_part, 0);
xl = strlen (expdir);
if (*directory_part == '~' && STREQ (directory_part, expdir))
{
/* tilde expansion failed, so what should we return? we use what the
user typed. */
v = mbschr (val, '/');
vl = STRLEN (v);
ret = (char *)xmalloc (xl + vl + 2);
strcpy (ret, directory_part);
if (v && *v)
strcpy (ret + xl, v);
free (dh2);
free (expdir);
return ret;
}
free (expdir);
/*
@@ -3010,6 +3026,11 @@ restore_tilde (val, directory_part)
l = length of remainder after tilde-prefix
*/
l = (vl - xl) + 1;
if (l <= 0)
{
free (dh2);
return (savestring (val)); /* XXX - just punt */
}
ret = (char *)xmalloc (dl2 + 2 + l);
strcpy (ret, dh2);
+6 -2
View File
@@ -247,6 +247,9 @@ printf_builtin (list)
char mbch[25]; /* 25 > MB_LEN_MAX, plus can handle 4-byte UTF-8 and large Unicode characters*/
int mbind, mblen;
#endif
#if defined (ARRAY_VARS)
int arrayflags;
#endif
conversion_error = 0;
retval = EXECUTION_SUCCESS;
@@ -261,7 +264,8 @@ printf_builtin (list)
case 'v':
vname = list_optarg;
#if defined (ARRAY_VARS)
if (legal_identifier (vname) || valid_array_reference (vname, assoc_expand_once))
arrayflags = assoc_expand_once ? (VA_NOEXPAND|VA_ONEWORD) : 0;
if (legal_identifier (vname) || valid_array_reference (vname, arrayflags))
#else
if (legal_identifier (vname))
#endif
@@ -1277,7 +1281,7 @@ bind_printf_variable (name, value, flags)
SHELL_VAR *v;
#if defined (ARRAY_VARS)
if (valid_array_reference (name, assoc_expand_once) == 0)
if (valid_array_reference (name, assoc_expand_once ? (VA_NOEXPAND|VA_ONEWORD) : 0) == 0)
v = bind_variable (name, value, flags);
else
v = assign_array_element (name, value, flags | (assoc_expand_once ? ASS_NOEXPAND : 0));
+8 -5
View File
@@ -179,7 +179,8 @@ read_builtin (list)
int size, nr, pass_next, saw_escape, eof, opt, retval, code, print_ps2, nflag;
volatile int i;
int input_is_tty, input_is_pipe, unbuffered_read, skip_ctlesc, skip_ctlnul;
int raw, edit, nchars, silent, have_timeout, ignore_delim, fd, lastsig, t_errno;
int raw, edit, nchars, silent, have_timeout, ignore_delim, fd;
int lastsig, t_errno;
int mb_cur_max;
unsigned int tmsec, tmusec;
long ival, uval;
@@ -192,6 +193,7 @@ read_builtin (list)
TTYSTRUCT ttattrs, ttset;
#if defined (ARRAY_VARS)
WORD_LIST *alist;
int vflags;
#endif
#if defined (READLINE)
char *rlbuf, *itext;
@@ -336,7 +338,8 @@ read_builtin (list)
/* Convenience: check early whether or not the first of possibly several
variable names is a valid identifier, and bail early if so. */
#if defined (ARRAY_VARS)
if (list && legal_identifier (list->word->word) == 0 && valid_array_reference (list->word->word, assoc_expand_once) == 0)
vflags = assoc_expand_once ? (VA_NOEXPAND|VA_ONEWORD) : 0;
if (list && legal_identifier (list->word->word) == 0 && valid_array_reference (list->word->word, vflags) == 0)
#else
if (list && legal_identifier (list->word->word) == 0)
#endif
@@ -853,7 +856,7 @@ assign_vars:
{
varname = list->word->word;
#if defined (ARRAY_VARS)
if (legal_identifier (varname) == 0 && valid_array_reference (varname, assoc_expand_once) == 0)
if (legal_identifier (varname) == 0 && valid_array_reference (varname, vflags) == 0)
#else
if (legal_identifier (varname) == 0)
#endif
@@ -901,7 +904,7 @@ assign_vars:
/* Now assign the rest of the line to the last variable argument. */
#if defined (ARRAY_VARS)
if (legal_identifier (list->word->word) == 0 && valid_array_reference (list->word->word, assoc_expand_once) == 0)
if (legal_identifier (list->word->word) == 0 && valid_array_reference (list->word->word, vflags) == 0)
#else
if (legal_identifier (list->word->word) == 0)
#endif
@@ -964,7 +967,7 @@ bind_read_variable (name, value)
SHELL_VAR *v;
#if defined (ARRAY_VARS)
if (valid_array_reference (name, assoc_expand_once) == 0)
if (valid_array_reference (name, assoc_expand_once ? (VA_NOEXPAND|VA_ONEWORD) : 0) == 0)
v = bind_variable (name, value, 0);
else
v = assign_array_element (name, value, assoc_expand_once ? ASS_NOEXPAND : 0);
+9 -4
View File
@@ -800,7 +800,7 @@ unset_builtin (list)
WORD_LIST *list;
{
int unset_function, unset_variable, unset_array, opt, nameref, any_failed;
int global_unset_func, global_unset_var;
int global_unset_func, global_unset_var, vflags;
char *name, *tname;
unset_function = unset_variable = unset_array = nameref = any_failed = 0;
@@ -837,6 +837,10 @@ unset_builtin (list)
else if (unset_function && nameref)
nameref = 0;
#if defined (ARRAY_VARS)
vflags = assoc_expand_once ? (VA_NOEXPAND|VA_ONEWORD) : 0;
#endif
while (list)
{
SHELL_VAR *var;
@@ -852,7 +856,8 @@ unset_builtin (list)
#if defined (ARRAY_VARS)
unset_array = 0;
if (!unset_function && nameref == 0 && valid_array_reference (name, assoc_expand_once)) /* XXX valid array reference second arg was 0 */
/* XXX valid array reference second arg was 0 */
if (!unset_function && nameref == 0 && valid_array_reference (name, vflags))
{
t = strchr (name, '[');
*t++ = '\0';
@@ -909,7 +914,7 @@ unset_builtin (list)
if (var && unset_array)
{
/* Let unbind_array_element decide what to do with non-array vars */
tem = unbind_array_element (var, t, assoc_expand_once); /* XXX new third arg */
tem = unbind_array_element (var, t, vflags); /* XXX new third arg */
if (tem == -2 && array_p (var) == 0 && assoc_p (var) == 0)
{
builtin_error (_("%s: not an array variable"), var->name);
@@ -932,7 +937,7 @@ unset_builtin (list)
{
tname = savestring (nameref_cell (var));
if (var = array_variable_part (tname, 0, &t, (int *)0))
tem = unbind_array_element (var, t, assoc_expand_once); /* XXX new third arg */
tem = unbind_array_element (var, t, vflags); /* XXX new third arg */
free (tname);
}
else
+1 -3
View File
@@ -1,7 +1,7 @@
This file is shopt.def, from which is created shopt.c.
It implements the Bash `shopt' builtin.
Copyright (C) 1994-2016 Free Software Foundation, Inc.
Copyright (C) 1994-2018 Free Software Foundation, Inc.
This file is part of GNU Bash, the Bourne Again SHell.
@@ -220,9 +220,7 @@ static struct {
{ "lithist", &literal_history, (shopt_set_func_t *)NULL },
#endif
{ "localvar_inherit", &localvar_inherit, (shopt_set_func_t *)NULL },
#if 0 /* bash-5.0-beta */
{ "localvar_unset", &localvar_unset, (shopt_set_func_t *)NULL },
#endif
{ "login_shell", &shopt_login_shell, set_login_shell },
{ "mailwarn", &mail_warning, (shopt_set_func_t *)NULL },
#if defined (READLINE)
+6 -1
View File
@@ -142,7 +142,7 @@
/* Define to 0 if you want the checkwinsize option off by default, 1 if you
want it on. */
#define CHECKWINSIZE_DEFAULT 0
#define CHECKWINSIZE_DEFAULT 1
/* Define to 1 if you want to optimize for sequential array assignment when
using indexed arrays, 0 if you want bash-4.2 behavior, which favors
@@ -180,3 +180,8 @@
/* Define to set the initial size of the history list ($HISTSIZE). This must
be a string. */
/*#define HISTSIZE_DEFAULT "500"*/
/* Define to 0 if you want history expansion to be disabled by default in
interactive shells; define to 1 for the historical behavior of enabling
when the shell is interactive. */
#define HISTEXPAND_DEFAULT 1
+12 -5
View File
@@ -5,12 +5,12 @@
.\" Case Western Reserve University
.\" chet.ramey@case.edu
.\"
.\" Last Change: Tue Aug 7 12:01:07 EDT 2018
.\" Last Change: Sat Sep 29 13:38:24 EDT 2018
.\"
.\" bash_builtins, strip all but Built-Ins section
.if \n(zZ=1 .ig zZ
.if \n(zY=1 .ig zY
.TH BASH 1 "2018 August 7" "GNU Bash 5.0"
.TH BASH 1 "2018 September 29" "GNU Bash 5.0"
.\"
.\" There's some problem with having a `@'
.\" in a tagged paragraph with the BSD man macros.
@@ -4409,12 +4409,12 @@ The levels are listed in order of decreasing precedence.
.B \fIid\fP++ \fIid\fP\-\-
variable post-increment and post-decrement
.TP
.B ++\fIid\fP \-\-\fIid\fP
variable pre-increment and pre-decrement
.TP
.B \- +
unary minus and plus
.TP
.B ++\fIid\fP \-\-\fIid\fP
variable pre-increment and pre-decrement
.TP
.B ! ~
logical and bitwise negation
.TP
@@ -9806,6 +9806,7 @@ command and, if necessary, updates the values of
and
.SM
.BR COLUMNS .
This option is enabled by default.
.TP 8
.B cmdhist
If set,
@@ -10105,6 +10106,12 @@ If set, local variables inherit the value and attributes of a variable of
the same name that exists at a previous scope before any new value is
assigned. The nameref attribute is not inherited.
.TP 8
.B localvar_unset
If set, calling \fBunset\fP on local variables in previous function scopes
marks them so subsequent lookups find them unset until that function
returns. This is identical to the behavior of unsetting local variables
at the current function scope.
.TP 8
.B login_shell
The shell sets this option if it is started as a login shell (see
.SM
+7
View File
@@ -5171,6 +5171,7 @@ The shell always postpones exiting if any jobs are stopped.
If set, Bash checks the window size after each external (non-builtin)
command and, if necessary, updates the values of
@env{LINES} and @env{COLUMNS}.
This option is enabled by default.
@item cmdhist
If set, Bash
@@ -5409,6 +5410,12 @@ If set, local variables inherit the value and attributes of a variable of
the same name that exists at a previous scope before any new value is
assigned. The @var{nameref} attribute is not inherited.
@item localvar_unset
If set, calling @code{unset} on local variables in previous function scopes
marks them so subsequent lookups find them unset until that function
returns. This is identical to the behavior of unsetting local variables
at the current function scope.
@item login_shell
The shell sets this option if it is started as a login shell
(@pxref{Invoking Bash}).
+3 -3
View File
@@ -2,10 +2,10 @@
Copyright (C) 1988-2018 Free Software Foundation, Inc.
@end ignore
@set LASTCHANGE Tue Aug 7 12:01:22 EDT 2018
@set LASTCHANGE Sat Sep 29 13:41:44 EDT 2018
@set EDITION 5.0
@set VERSION 5.0
@set UPDATED 7 August 2018
@set UPDATED-MONTH August 2018
@set UPDATED 29 September 2018
@set UPDATED-MONTH September 2018
+4 -4
View File
@@ -2873,14 +2873,14 @@ space_to_eol (int count)
void
_rl_clear_screen (void)
{
#ifndef __DJGPP__
#if defined (__DJGPP__)
ScreenClear ();
ScreenSetCursor (0, 0);
#else
if (_rl_term_clrpag)
tputs (_rl_term_clrpag, 1, _rl_output_character_function);
else
rl_crlf ();
#else
ScreenClear ();
ScreenSetCursor (0, 0);
#endif /* __DJGPP__ */
}
+16 -2
View File
@@ -102,15 +102,29 @@ static int rl_gather_tyi PARAMS((void));
/* Windows isatty returns true for every character device, including the null
device, so we need to perform additional checks. */
#if defined (_WIN32) && !defined (__CYGWIN__)
#include <conio.h>
#include <io.h>
#include <conio.h>
#define WIN32_LEAN_AND_MEAN 1
#include <windows.h>
int
win32_isatty (int fd)
{
return (_isatty (fd) ? ((((long) (HANDLE) _get_osfhandle (fd)) & 3) == 3) : 0);
if (_isatty(fd))
{
HANDLE h;
DWORD ignored;
if ((h = (HANDLE) _get_osfhandle (fd)) == INVALID_HANDLE_VALUE)
{
errno = EBADF;
return 0;
}
if (GetConsoleMode (h, &ignored) != 0)
return 1;
}
errno = ENOTTY;
return 0;
}
#define isatty(x) win32_isatty(x)
+869 -1356
View File
File diff suppressed because it is too large Load Diff
+3
View File
@@ -1816,6 +1816,9 @@ skip_matched_pair (string, start, open, close, flags)
}
#if defined (ARRAY_VARS)
/* Flags has 1 as a reserved value, since skip_matched_pair uses it for
skipping over quoted strings and taking the first instance of the
closing character. */
int
skipsubscript (string, start, flags)
const char *string;
+1 -1
View File
@@ -1,4 +1,4 @@
BUILD_DIR=/usr/local/build/chet/bash/bash-current
BUILD_DIR=/usr/local/build/bash/bash-current
THIS_SH=$BUILD_DIR/bash
PATH=$PATH:$BUILD_DIR
+15
View File
@@ -741,3 +741,18 @@ argv[2] = <b>
argv[1] = <a>
argv[2] = <b>
argv[1] = <a+b>
7
./array27.sub: line 11: a[]]=7 : syntax error: invalid arithmetic operator (error token is "]=7 ")
declare -A A=([$'\t']="2" [" "]="2" )
./array27.sub: line 23: ((: A[]]=2 : syntax error: invalid arithmetic operator (error token is "]=2 ")
declare -A A=([$'\t']="2" [" "]="2" ["*"]="2" ["@"]="2" )
./array27.sub: line 32: A[]]: bad array subscript
declare -A A=([$'\t']="X" [" "]="X" ["*"]="X" ["@"]="X" )
./array27.sub: line 40: A[]]: bad array subscript
declare -A A=([$'\t']="X" [" "]="X" ["*"]="X" ["@"]="X" )
./array27.sub: line 48: declare: `A[]]=X': not a valid identifier
declare -A A=(["*"]="X" ["@"]="X" )
./array27.sub: line 56: declare: `A[]]=X': not a valid identifier
./array27.sub: line 56: A[*]: bad array subscript
./array27.sub: line 56: A[@]: bad array subscript
declare -A A
+1
View File
@@ -405,3 +405,4 @@ ${THIS_SH} ./array23.sub
${THIS_SH} ./array24.sub
${THIS_SH} ./array25.sub
${THIS_SH} ./array26.sub
${THIS_SH} ./array27.sub
+59
View File
@@ -0,0 +1,59 @@
# tests for `problem' keys when using associative arrays and assoc_expand_once
# deal with problems for now; this is a placeholder for if and when I fix them
typeset -A a
shopt -s assoc_expand_once
k='['
echo $(( a[$k]=7 ))
k=']'
echo $(( a[$k]=7 ))
unset a
declare -A A
for k in $'\t' ' '; do
(( A[$k]=2 ))
done
declare -p A
for k in ']' '*' '@'; do
(( A[$k]=2 ))
done
declare -p A
unset A
declare -A A
for k in $'\t' ' ' ']' '*' '@'; do
read "A[$k]" <<< X
done
declare -p A
unset A
declare -A A
for k in $'\t' ' ' ']' '*' '@'; do
printf -v "A[$k]" "%s" X
done
declare -p A
unset A
declare -A A
for k in ']' '*' '@'; do
declare A[$k]=X
done
declare -p A
unset A
declare -A A
for k in ']' '*' '@'; do
declare "A[$k]=X"
done
declare -p A