Fix insufficient slice check (#2755)

This commit is contained in:
raymonder jin 2021-06-25 13:22:01 +08:00 committed by GitHub
parent f2bbdfe9f2
commit 1d0f938f28
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 1 deletions

View File

@ -459,7 +459,7 @@ walk: // Outer loop for walking the tree
}
// Save param value
if params != nil {
if params != nil && cap(*params) > 0 {
if value.params == nil {
value.params = params
}

View File

@ -717,6 +717,19 @@ func TestTreeInvalidNodeType(t *testing.T) {
}
}
func TestTreeInvalidParamsType(t *testing.T) {
tree := &node{}
tree.wildChild = true
tree.children = append(tree.children, &node{})
tree.children[0].nType = 2
// set invalid Params type
params := make(Params, 0, 0)
// try to trigger slice bounds out of range with capacity 0
tree.getValue("/test", &params, false)
}
func TestTreeWildcardConflictEx(t *testing.T) {
conflicts := [...]struct {
route string