Ignore too large indices in parse_slice

Fixes #4127.
This commit is contained in:
Fabian Homborg 2017-06-16 14:17:17 +02:00 committed by Kurtis Rader
parent 44f2f37bd4
commit 897dba9f07
3 changed files with 15 additions and 1 deletions

View File

@ -650,7 +650,7 @@ static size_t parse_slice(const wchar_t *in, wchar_t **end_ptr, std::vector<long
}
// debug( 0, L"Push idx %d", tmp );
long i1 = tmp > -1 ? tmp : (long)array_size + tmp + 1;
long i1 = tmp > -1 ? tmp : size + tmp + 1;
pos = end - in;
while (in[pos] == INTERNAL_SEPARATOR) pos++;
if (in[pos] == L'.' && in[pos + 1] == L'.') {
@ -667,6 +667,13 @@ static size_t parse_slice(const wchar_t *in, wchar_t **end_ptr, std::vector<long
// debug( 0, L"Push range %d %d", tmp, tmp1 );
long i2 = tmp1 > -1 ? tmp1 : size + tmp1 + 1;
// Clamp to array size, but only when doing a range,
// and only when just one is too high.
if (i1 > size && i2 > size) {
continue;
}
i1 = i1 < size ? i1 : size;
i2 = i2 < size ? i2 : size;
// debug( 0, L"Push range idx %d %d", i1, i2 );
short direction = i2 < i1 ? -1 : 1;
for (long jjj = i1; jjj * direction <= i2 * direction; jjj += direction) {

View File

@ -80,6 +80,10 @@ show "$foo[1 2]"
show $foo[1 2]
show "$foo[2 1]"
show $foo[2 1]
set -l foo a b c
show $foo[17]
show $foo[-17]
show $foo[17..18]
echo "$foo[d]"
echo $foo[d]

View File

@ -52,5 +52,8 @@
0
1
0
0
0
0
Catch your breath