Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions framework/override_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,10 @@ func overridePathInArray(input []interface{}, path []string, isDelete bool, valu
return output, nil
}

if pathIndex < 0 || pathIndex >= len(output) {
return nil, fmt.Errorf("cannot set '%d' in array: out of range", pathIndex)
}

switch typed := output[pathIndex].(type) {
case map[string]interface{}:
subOutput, err := overridePathInMap(typed, path[1:], isDelete, value)
Expand Down
14 changes: 14 additions & 0 deletions framework/override_utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,20 @@ func TestWritePathInStruct(t *testing.T) {
Value: "hello",
ExpectedError: fmt.Errorf("a: cannot set '2' in array: out of range"),
},
{
Name: "nested index out of range",
Spec: `{"a": [{}]}`,
Path: []string{"a", "2", "c"},
Value: "hello",
ExpectedError: fmt.Errorf("a: cannot set '2' in array: out of range"),
},
{
Name: "nested negative index",
Spec: `{"a": [{}]}`,
Path: []string{"a", "-1", "c"},
Value: "hello",
ExpectedError: fmt.Errorf("a: cannot set '-1' in array: out of range"),
},
{
Name: "no append nested arrays",
Spec: `{"a":[[0]]}`,
Expand Down