declare builtin changes to reject -i when used with -n; readline changes to make control characters visible in search strings; readline signal handling changes to avoid data corruption and UAF; documentation updates for more consistent quoting

This commit is contained in:
Chet Ramey
2025-09-04 12:29:57 -04:00
parent ab17ddb7af
commit a451bfc3f5
46 changed files with 36912 additions and 1499 deletions
+58 -25
View File
@@ -1,12 +1,12 @@
./array.tests: line 34: syntax error near unexpected token `&'
./array.tests: line 34: `test=(first & second)'
./array.tests: line 35: syntax error near unexpected token `&'
./array.tests: line 35: `test=(first & second)'
1
abcde
abcde
abcde bdef
abcde bdef
declare -a BASH_ARGC=()
declare -a BASH_ARGC=([0]="0")
declare -a BASH_ARGV=()
declare -a BASH_LINENO=([0]="0")
declare -a BASH_SOURCE=([0]="./array.tests")
@@ -26,7 +26,7 @@ hello world
11
3
bdef hello world test expression test 2
./array.tests: line 98: readonly: `a[5]': not a valid identifier
./array.tests: line 99: readonly: `a[5]': not a valid identifier
declare -ar a=([1]="" [2]="bdef" [5]="hello world" [6]="test expression" [15]="test 2")
declare -ar c
declare -ar a=([1]="" [2]="bdef" [5]="hello world" [6]="test expression" [15]="test 2")
@@ -34,7 +34,7 @@ declare -ar c
readonly -a a=([1]="" [2]="bdef" [5]="hello world" [6]="test expression" [15]="test 2")
readonly -a c
a test
declare -a BASH_ARGC=()
declare -a BASH_ARGC=([0]="0")
declare -a BASH_ARGV=()
declare -a BASH_LINENO=([0]="0")
declare -a BASH_SOURCE=([0]="./array.tests")
@@ -46,18 +46,18 @@ declare -ar c
declare -a d=([1]="" [2]="bdef" [5]="hello world" [6]="test" [9]="ninth element")
declare -a e=([0]="test")
declare -a f=([0]="" [1]="bdef" [2]="hello world" [3]="test" [4]="ninth element")
./array.tests: line 122: a: readonly variable
./array.tests: line 124: b[]: bad array subscript
./array.tests: line 125: b[*]: bad array subscript
./array.tests: line 123: a: readonly variable
./array.tests: line 125: b[]: bad array subscript
./array.tests: line 126: b[*]: bad array subscript
this
./array.tests: line 128: c[-2]: bad array subscript
./array.tests: line 129: c: bad array subscript
./array.tests: line 129: c[-2]: bad array subscript
./array.tests: line 130: c: bad array subscript
./array.tests: line 131: d[7]: cannot assign list to array member
./array.tests: line 133: []=abcde: bad array subscript
./array.tests: line 134: [*]=last: cannot assign to non-numeric index
./array.tests: line 135: [-65]=negative: bad array subscript
declare -a BASH_ARGC=()
./array.tests: line 132: d[7]: cannot assign list to array member
./array.tests: line 134: []=abcde: bad array subscript
./array.tests: line 135: [*]=last: cannot assign to non-numeric index
./array.tests: line 136: [-65]=negative: bad array subscript
declare -a BASH_ARGC=([0]="0")
declare -a BASH_ARGV=()
declare -a BASH_LINENO=([0]="0")
declare -a BASH_SOURCE=([0]="./array.tests")
@@ -69,13 +69,13 @@ declare -ar c
declare -a d=([1]="test test")
declare -a e=()
declare -a f=([0]="" [1]="bdef" [2]="hello world" [3]="test" [4]="ninth element")
./array.tests: line 143: unset: ps1: not an array variable
./array.tests: line 147: declare: c: readonly variable
./array.tests: line 144: unset: ps1: not an array variable
./array.tests: line 148: declare: c: readonly variable
this of
this is a test of read using arrays
this test
this is a test of arrays
declare -a BASH_ARGC=()
declare -a BASH_ARGC=([0]="0")
declare -a BASH_ARGV=()
declare -a BASH_LINENO=([0]="0")
declare -a BASH_SOURCE=([0]="./array.tests")
@@ -123,7 +123,7 @@ argv[1] = </>
55
49
6 -- 6
./array.tests: line 238: [-10]: bad array subscript
./array.tests: line 239: [-10]: bad array subscript
0
42 14 44
grep [ 123 ] *
@@ -131,20 +131,24 @@ grep [ 123 ] *
6 7 9 5
length = 3
value = new1 new2 new3
./array.tests: line 267: syntax error near unexpected token `&'
./array.tests: line 267: `badarray=( metacharacters like & need to be quoted in compound assignments)'
./array.tests: line 271: narray[4]: unbound variable
./array.tests: line 268: syntax error near unexpected token `&'
./array.tests: line 268: `badarray=( metacharacters like & need to be quoted in compound assignments)'
./array.tests: line 272: narray[4]: unbound variable
array1.sub
./array1.sub: line 1: syntax error near unexpected token `('
./array1.sub: line 1: `printf "%s\n" -a a=(a 'b c')'
array2.sub
./array2.sub: line 1: declare: `[]=asdf': not a valid identifier
./array2.sub: line 2: a[]: bad array subscript
./array2.sub: line 4: syntax error near unexpected token `('
./array2.sub: line 4: `declare -a ''=(a 'b c')'
array3.sub
9
9
7 8 9
array4.sub
8 11
8 11
6
@@ -160,10 +164,10 @@ for case if then else
12 14 16 18 20
4414758999202
aaa bbb
./array.tests: line 321: syntax error near unexpected token `<>'
./array.tests: line 321: `metas=( <> < > ! )'
./array.tests: line 322: syntax error near unexpected token `<>'
./array.tests: line 322: `metas=( [1]=<> [2]=< [3]=> [4]=! )'
./array.tests: line 322: `metas=( <> < > ! )'
./array.tests: line 323: syntax error near unexpected token `<>'
./array.tests: line 323: `metas=( [1]=<> [2]=< [3]=> [4]=! )'
abc 3
case 4
abc case if then else 5
@@ -217,11 +221,13 @@ FIN3:0
FIN4:0
FIN5:0
FIN6:0
array5.sub
t
[3]=abcde r s t u v
e
9
2
array6.sub
a b c
argv[1] = <-iname 'a>
argv[2] = <-iname 'b>
@@ -284,6 +290,7 @@ argv[1] = <element1 with spaces>
argv[2] = <element2 with spaces>
argv[1] = <element1 with spaces>
argv[2] = <element2 with spaces>
array7.sub
nord!olz
rdholz
@@ -292,6 +299,7 @@ rdholz
rdho
array8.sub
argv[1] = <fooq//barq/>
argv[1] = <fooq>
argv[2] = <>
@@ -317,6 +325,7 @@ argv[1] = <FOOQ>
argv[2] = <>
argv[3] = <BARQ>
argv[4] = <>
array9.sub
126
127
128
@@ -330,6 +339,7 @@ argv[3] = <
argv[1] = <~>
argv[2] = <^?>
argv[3] = <€>
array10.sub
Monday Tuesday Wednesday Thursday Friday Saturday Sunday
Monday
Monday
@@ -359,6 +369,7 @@ ednesday
onday
uesday
ednesday
array11.sub
version[agent]
version.agent
version[agent]
@@ -369,15 +380,18 @@ foobar] foo foo[bar]
bleh bbb bleh
ab]
bar
array12.sub
1
1
1
1
1
1
array13.sub
main main
function function
function function
array14.sub
declare -a x=([0]="0" [1]="1" [2]="2" [3]="3" [4]="4" [5]="5")
declare -a x=([0]="0" [1]="1" [2]="2" [3]="3" [4]="4")
declare -a x=([0]="0" [1]="1" [2]="2" [4]="4")
@@ -389,6 +403,7 @@ declare -a x=([0]="0" [1]="1" [2]="2" [3]="3" [4]="4" [5]="foo")
declare -a x=([0]="0" [1]="1" [2]="2" [3]="3" [4]="4" [5]="5")
declare -a x=([0]="0" [1]="1" [2]="2" [3]="3" [4]="4four" [5]="5")
strlen(4four) = 5
array15.sub
1 2 0 3
1 2 0 3
1 2 0 3
@@ -396,6 +411,7 @@ strlen(4four) = 5
1 2 0 3
declare -ai arr=([0]="2" [1]="4" [2]="6")
declare -a arr=([0]="hello" [1]="world")
array16.sub
foo index 1: ok
foo index 2: ok
foo: implicit reference to element 0: ok
@@ -408,6 +424,7 @@ qux: unset array element 0: ok
0
0
0
array17.sub
2
2
2
@@ -431,6 +448,7 @@ one
two
two
./array17.sub: line 89: ~ : arithmetic syntax error: operand expected (error token is "~ ")
array18.sub
1
argv[1] = <>
argv[2] = <>
@@ -454,6 +472,7 @@ argv[1] = <qux>
argv[1] = <->
argv[2] = <->
argv[1] = < >
array19.sub
declare -a foo=([0]="( zeroind )")
declare -a foo=([0]="zeroind")
declare -a foo=([0]="zeroind")
@@ -498,6 +517,7 @@ declare -A b=([0]="/scratch/bash" )
declare -A c=([1]="2" )
declare -A d=(["a b"]="" )
declare -A e=([Darwin]="" )
array20.sub
a+b+c
x+b+c
a+b+c
@@ -508,6 +528,7 @@ a b c
x b c
a b c
x b c
array21.sub
declare -a a=([1]="2" [2]="3" [3]="4")
abcd
unset
@@ -516,6 +537,7 @@ declare -A A=([four]="4" [two]="2" [three]="3" [one]="1" )
declare -a a=()
declare -A A=()
declare -a foo=([0]="1" [1]="(4 5 6)" [2]="3")
array22.sub
a1
argv[1] = <>
argv[2] = <>
@@ -537,6 +559,7 @@ p3
argv[1] = <y>
<X> <X> <X> <X>
<X> <X> <X> <X>
array23.sub
./array23.sub: line 22: $( echo >&2 foo ) : arithmetic syntax error: operand expected (error token is "$( echo >&2 foo ) ")
./array23.sub: line 23: $( echo >&2 foo ) : arithmetic syntax error: operand expected (error token is "$( echo >&2 foo ) ")
./array23.sub: line 24: $( echo >&2 foo ) : arithmetic syntax error: operand expected (error token is "$( echo >&2 foo ) ")
@@ -548,6 +571,7 @@ argv[1] = <y>
0
0
0
array24.sub
IFS=: ${var-$*}
abc
def ghi
@@ -595,6 +619,7 @@ jkl
abc
def ghi
jkl
array25.sub
1. indexed:
reference:
1. 0
@@ -639,6 +664,7 @@ arithmetic:
6.declare -A a=([1]="1" [0]="0" [" "]="10" ["\" \""]="11" )
7.declare -A a=([1]="1" [0]="0" [" "]="12" ["\" \""]="11" )
8.declare -A a=([1]="1" [0]="0" [" "]="12" ["\" \""]="13" )
array26.sub
argv[1] = <aa>
argv[2] = <bb>
argv[1] = <aa>
@@ -759,6 +785,7 @@ argv[2] = <a>
argv[1] = <b>
argv[2] = <a>
argv[1] = <b+a>
array27.sub
7
7
declare -A A=([$'\t']="2" [" "]="2" )
@@ -774,12 +801,14 @@ declare -A A=(["*"]="X" ["@"]="X" )
declare -A A=(["*"]="X" ["@"]="X" )
./array27.sub: line 81: y[]: bad array subscript
./array27.sub: line 81: y[]: bad array subscript
array28.sub
declare -a bug4=([0]="" [1]="5" [2]="" [3]="1" [4]="")
declare -a bug=([0]="" [1]="5" [2]="" [3]="1" [4]="")
declare -a bug2=([0]="")
declare -a bug3=([0]="" [1]="5" [2]="" [3]="1" [4]="")
declare -a not_bug=([0]="no" [1]="nulls")
declare -a workaround=([0]="")
array29.sub
declare -a var=([0]=$'\001\001\001\001')
declare -A v2=([$'\001']=$'ab\001c' )
declare -a foo=([0]=$'\001\001\001\001')
@@ -790,6 +819,7 @@ declare -A foo=([v]=$'\001\001\001\001' )
declare -A foo=([v]=$'\001\001\001\001' )
declare -A foo=([$'\001']=$'ab\001c' )
declare -A foo=([$'\001']=$'ab\001c' )
array30.sub
foo
declare -a a=([42]="foo")
foo
@@ -802,12 +832,14 @@ FOO
declare -Au A=([Darwin]="FOO" )
FOO
declare -Au A=(["@"]="FOO" )
array31.sub
declare -a aa=([0]="/homes/cj/Desktop")
declare -a aa=([0]="/homes/cj/Desktop")
declare -a aa=([0]="/homes/cj/Desktop:/homes/cj/Library:/homes/cj/Documents")
declare -a aa=([0]="/homes/cj/Desktop:/homes/cj/Library:/homes/cj/Documents")
declare -a aa=([0]="/homes/cj/Desktop:/homes/cj/Library:/homes/cj/Documents" [1]="/homes/cj/Applications")
declare -a aa=([0]="/homes/cj/Desktop:/homes/cj/Library:/homes/cj/Documents" [1]="/homes/cj/Applications")
array32.sub
./array32.sub: line 20: $(echo INJECTION! >&2 ; echo 0): arithmetic syntax error: operand expected (error token is "$(echo INJECTION! >&2 ; echo 0)")
./array32.sub: line 21: declare: a: not found
./array32.sub: line 24: $(echo INJECTION! >&2 ; echo 0): arithmetic syntax error: operand expected (error token is "$(echo INJECTION! >&2 ; echo 0)")
@@ -837,6 +869,7 @@ declare -a a
declare -a a=()
./array32.sub: line 95: $(echo INJECTION! >&2 ; echo 0): arithmetic syntax error: operand expected (error token is "$(echo INJECTION! >&2 ; echo 0)")
declare -a a=()
array33.sub
declare -A A=([x]="x" )
declare -A A=([1]="1" )
./array33.sub: line 27: f: A: cannot convert associative to indexed array