From e683842359c67564ad35ce4d4dc420915f612357 Mon Sep 17 00:00:00 2001 From: deads2k Date: Mon, 9 Nov 2015 11:01:57 -0500 Subject: [PATCH] stop panicing on bad array length --- pkg/util/jsonpath/jsonpath.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/pkg/util/jsonpath/jsonpath.go b/pkg/util/jsonpath/jsonpath.go index 7d4b7620995..f989948683a 100644 --- a/pkg/util/jsonpath/jsonpath.go +++ b/pkg/util/jsonpath/jsonpath.go @@ -234,6 +234,16 @@ func (j *JSONPath) evalArray(input []reflect.Value, node *ArrayNode) ([]reflect. params[1].Value += value.Len() } + sliceLength := value.Len() + if params[1].Value != params[0].Value { // if you're requesting zero elements, allow it through. + if params[0].Value >= sliceLength { + return input, fmt.Errorf("array index out of bounds: index %d, length %d", params[0].Value, sliceLength) + } + if params[1].Value > sliceLength { + return input, fmt.Errorf("array index out of bounds: index %d, length %d", params[1].Value-1, sliceLength) + } + } + if !params[2].Known { value = value.Slice(params[0].Value, params[1].Value) } else {