mirror of
https://https.git.savannah.gnu.org/git/bash.git
synced 2026-07-06 20:00:49 +02:00
change overflow behavior in fltexpr; fix for readline event hook; fix for internal quoting of array subscripts in arithmetic expression contexts
This commit is contained in:
@@ -11344,3 +11344,22 @@ builtins/printf.def
|
||||
- printstr: only adjust precision if the decoded precision is >= 0,
|
||||
since decodeint returns -1 on overflow/failure
|
||||
|
||||
lib/readline/input.c
|
||||
- _rl_gather_tyi: if the input-available hook returns success,
|
||||
indicating that input is available, set chars_avail to 1, assuming
|
||||
there is at minimum a single character of input available
|
||||
- _rl_gather_tyi: if pselect/select return non-zero, indicating that
|
||||
input is available, set result = -1 before going on so subsequent
|
||||
branches will check how many chars are available and set chars_avail
|
||||
Report from Dmitri A. Sergatskov <dasergatskov@gmail.com>
|
||||
|
||||
7/10
|
||||
----
|
||||
subst.c
|
||||
- ARITH_EXP_CHARS: remove ~ from set because we don't perform tilde
|
||||
expansion when expanding arithmetic expressions
|
||||
- string_quote_removal: if quoted includes Q_ARITH, indicating we are
|
||||
expanding an arithmetic expression for a compound command or array
|
||||
subscript, remove backslashes quoting `[', `]', and `~', since those
|
||||
are quoted by expand_array_subscript but not dequoted anywhere else
|
||||
Fixes quoting bug reported by Isabella Bosia <izaberina@gmail.com>
|
||||
|
||||
@@ -970,6 +970,7 @@ tests/arith7.sub f
|
||||
tests/arith8.sub f
|
||||
tests/arith9.sub f
|
||||
tests/arith10.sub f
|
||||
tests/arith11.sub f
|
||||
tests/array.tests f
|
||||
tests/array.right f
|
||||
tests/array1.sub f
|
||||
|
||||
@@ -148,6 +148,7 @@ typedef double sh_float_t;
|
||||
#define SHFLOAT_MANT_DIG DBL_MANT_DIG
|
||||
#define SHFLOAT_LENGTH_MODIFIER 'l';
|
||||
#define SHFLOAT_STRTOD strtod
|
||||
#define SHFLOAT_HUGE_VAL HUGE_VAL
|
||||
|
||||
#ifndef M_EGAMMA
|
||||
#define M_EGAMMA 0.57721566490153286060651209008240243
|
||||
@@ -489,9 +490,11 @@ fltexpr_strtod (const char *nptr, char **ep)
|
||||
|
||||
errno = 0;
|
||||
r = SHFLOAT_STRTOD (nptr, &xp);
|
||||
if (errno == ERANGE)
|
||||
if (errno == ERANGE && (r == SHFLOAT_HUGE_VAL || r == -SHFLOAT_HUGE_VAL))
|
||||
r = (r == SHFLOAT_HUGE_VAL) ? infval : -infval;
|
||||
else if (errno == ERANGE)
|
||||
evalerror ("number out of range");
|
||||
else if (r == 0 && *ep == nptr)
|
||||
else if (r == 0 && xp == nptr)
|
||||
evalerror ("invalid number");
|
||||
if (ep)
|
||||
*ep = xp;
|
||||
|
||||
@@ -27,7 +27,8 @@
|
||||
#include "stdc.h"
|
||||
|
||||
/* Functions from expr.c. */
|
||||
#define EXP_EXPANDED 0x01
|
||||
#define EXP_EXPANDED 0x01 /* already expanded */
|
||||
#define EXP_QUOTED 0x02 /* expanded, needs internal quote removal, not used yet */
|
||||
|
||||
extern intmax_t evalexp (const char *, int, int *);
|
||||
|
||||
|
||||
@@ -261,13 +261,16 @@ rl_gather_tyi (void)
|
||||
input = 0;
|
||||
tty = fileno (rl_instream);
|
||||
|
||||
/* Move this up here to give it first shot, but it can't set chars_avail */
|
||||
/* Move this up here to give it first shot, but it can't set chars_avail,
|
||||
so we assume a single character is available. */
|
||||
/* XXX - need rl_chars_available_hook? */
|
||||
if (rl_input_available_hook)
|
||||
{
|
||||
result = (*rl_input_available_hook) ();
|
||||
if (result == 0)
|
||||
result = -1;
|
||||
else
|
||||
chars_avail = 1;
|
||||
}
|
||||
|
||||
#if defined (HAVE_PSELECT) || defined (HAVE_SELECT)
|
||||
@@ -285,6 +288,7 @@ rl_gather_tyi (void)
|
||||
#endif
|
||||
if (result <= 0)
|
||||
return 0; /* Nothing to read. */
|
||||
result = -1; /* there is something, so check how many chars below */
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
@@ -3795,9 +3795,9 @@ pos_params (const char *string, int start, int end, int quoted, int pflags)
|
||||
#define EXP_CHAR(s) (s == '$' || s == '`' || s == CTLESC || s == '~')
|
||||
#endif
|
||||
|
||||
/* We don't perform process substitution in arithmetic expressions, so don't
|
||||
bother checking for it. */
|
||||
#define ARITH_EXP_CHAR(s) (s == '$' || s == '`' || s == CTLESC || s == '~')
|
||||
/* We don't perform process substitution or tilde expansion in arithmetic
|
||||
expressions, so don't bother checking for them. */
|
||||
#define ARITH_EXP_CHAR(s) (s == '$' || s == '`' || s == CTLESC)
|
||||
|
||||
/* If there are any characters in STRING that require full expansion,
|
||||
then call FUNC to expand STRING; otherwise just perform quote
|
||||
@@ -12215,6 +12215,14 @@ string_quote_removal (const char *string, int quoted)
|
||||
*r++ = '\\';
|
||||
break;
|
||||
}
|
||||
#if defined (ARRAY_VARS)
|
||||
/* The only special characters that matter here are []~, since those
|
||||
are backslash-quoted in expand_array_subscript but not dequoted
|
||||
by the statement following this one. */
|
||||
if ((quoted & Q_ARITH) && (c == LBRACK || c == RBRACK || c == '~'))
|
||||
; /* placeholder here */
|
||||
else
|
||||
#endif
|
||||
if (((quoted & (Q_HERE_DOCUMENT|Q_DOUBLE_QUOTES)) || dquote) && (sh_syntaxtab[c] & CBSDQUOTE) == 0)
|
||||
*r++ = '\\';
|
||||
/* FALLTHROUGH */
|
||||
|
||||
+14
-5
@@ -355,15 +355,24 @@ declare -a a=([0]="0")
|
||||
3 1
|
||||
./arith10.sub: line 95: let: 0 - "": arithmetic syntax error: operand expected (error token is """")
|
||||
4 1
|
||||
0
|
||||
declare -a yy=([0]="10")
|
||||
|
||||
./arith11.sub: line 46: $(echo xxxx) : arithmetic syntax error: operand expected (error token is "$(echo xxxx) ")
|
||||
./arith11.sub: line 47: $(echo xxxx): arithmetic syntax error: operand expected (error token is "$(echo xxxx)")
|
||||
./arith11.sub: line 48: $(echo xxxx): arithmetic syntax error: operand expected (error token is "$(echo xxxx)")
|
||||
0
|
||||
Y
|
||||
./arith11.sub: line 65: 'foo' : arithmetic syntax error: operand expected (error token is "'foo' ")
|
||||
8 12
|
||||
./arith.tests: line 335: ((: x=9 y=41 : arithmetic syntax error in expression (error token is "y=41 ")
|
||||
./arith.tests: line 339: a b: arithmetic syntax error in expression (error token is "b")
|
||||
./arith.tests: line 340: ((: a b: arithmetic syntax error in expression (error token is "b")
|
||||
./arith.tests: line 338: ((: x=9 y=41 : arithmetic syntax error in expression (error token is "y=41 ")
|
||||
./arith.tests: line 342: a b: arithmetic syntax error in expression (error token is "b")
|
||||
./arith.tests: line 343: ((: a b: arithmetic syntax error in expression (error token is "b")
|
||||
42
|
||||
42
|
||||
42
|
||||
42
|
||||
42
|
||||
42
|
||||
./arith.tests: line 355: 'foo' : arithmetic syntax error: operand expected (error token is "'foo' ")
|
||||
./arith.tests: line 358: b[c]d: arithmetic syntax error in expression (error token is "d")
|
||||
./arith.tests: line 358: 'foo' : arithmetic syntax error: operand expected (error token is "'foo' ")
|
||||
./arith.tests: line 361: b[c]d: arithmetic syntax error in expression (error token is "d")
|
||||
|
||||
@@ -324,6 +324,9 @@ ${THIS_SH} ./arith9.sub
|
||||
# empty expressions in various arithmetic evaluation contexts
|
||||
${THIS_SH} ./arith10.sub
|
||||
|
||||
# internal quoting for array subscripts
|
||||
${THIS_SH} ./arith11.sub
|
||||
|
||||
x=4
|
||||
y=7
|
||||
|
||||
|
||||
@@ -0,0 +1,65 @@
|
||||
# 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/>.
|
||||
#
|
||||
# make sure all internal backslash quoting for array subscripts in arithmetic
|
||||
# contexts is removed appropriately before the expression is evaluated
|
||||
|
||||
a=(0 1 2)
|
||||
b=(0 1 2)
|
||||
x=0
|
||||
|
||||
((i=$x,a[b[i]]))
|
||||
let "i=$x,a[b[i]]"
|
||||
|
||||
echo $((i=$x,a[b[i]]))
|
||||
for (( i=$x,a[b[i]]; i != 0; i--)); do echo a; done
|
||||
|
||||
yy[i=$x,a[b[i]]]=10
|
||||
declare -p yy
|
||||
unset yy
|
||||
|
||||
declare -i yy
|
||||
yy=i=$x,a[b[i]]
|
||||
unset yy
|
||||
|
||||
[[ i=$x,a[b[i]] -gt 0 ]]
|
||||
|
||||
echo ${var:i=$x,a[b[i]]:4}
|
||||
|
||||
unset i a b
|
||||
|
||||
xxxx=4
|
||||
foo='$(echo xxxx)'
|
||||
|
||||
# errors
|
||||
|
||||
echo $(( $foo ))
|
||||
echo $(( b[~foo/$xxxx] )) # still attempts tilde expansion
|
||||
echo $(( b[~foo * $xxxx] ))
|
||||
|
||||
# but associative arrays work, not arithmetic expressions
|
||||
typeset -A b
|
||||
xxxx=4
|
||||
foo='$(echo comsub)'
|
||||
|
||||
echo $(( b[~foo * $xxxx] ))
|
||||
|
||||
# original report
|
||||
|
||||
x[3]=10 i=3 a[5]=42 p=15
|
||||
# comparison throws error
|
||||
(( a[p - x[i]] > 10)) && echo Y
|
||||
|
||||
# errors
|
||||
foo=1
|
||||
echo $(( 'foo' ))
|
||||
@@ -44,7 +44,7 @@ declare -A assoc=(["\` echo >&2 foo\`"]="128" [0]="0" ["]"]="12" ["x],b[\$(echo
|
||||
foo
|
||||
0
|
||||
0
|
||||
./quotearray1.sub: line 68: 0\],b\[1: arithmetic syntax error: invalid arithmetic operator (error token is "\],b\[1")
|
||||
./quotearray1.sub: line 68: 0],b[1: arithmetic syntax error: invalid arithmetic operator (error token is "],b[1")
|
||||
declare -a array
|
||||
0
|
||||
0
|
||||
|
||||
Reference in New Issue
Block a user