core: check for negative indices in ResourceConfig.get
The bounds checking in ResourceConfig.get() was insufficient: it detected when the index was greater than or equal to cv.Len() but not when the index was less than zero. If the user provided an (invalid) configuration that referenced "foo.-1.bar", the provider would panic. Now it behaves the same way as if the index were too high.
This commit is contained in:
parent
f1079257ac
commit
6680b1f16b
|
@ -346,7 +346,7 @@ func (c *ResourceConfig) get(
|
|||
if err != nil {
|
||||
return nil, false
|
||||
}
|
||||
if i >= int64(cv.Len()) {
|
||||
if int(i) < 0 || int(i) >= cv.Len() {
|
||||
return nil, false
|
||||
}
|
||||
current = cv.Index(int(i)).Interface()
|
||||
|
|
|
@ -158,6 +158,14 @@ func TestResourceConfigGet(t *testing.T) {
|
|||
Value: nil,
|
||||
},
|
||||
|
||||
{
|
||||
Config: map[string]interface{}{
|
||||
"foo": []interface{}{1, 2, 5},
|
||||
},
|
||||
Key: "foo.-1",
|
||||
Value: nil,
|
||||
},
|
||||
|
||||
// get from map
|
||||
{
|
||||
Config: map[string]interface{}{
|
||||
|
|
Loading…
Reference in New Issue