Skip to content

Commit

Permalink
Fix insufficient slice check (gin-gonic#2755)
Browse files Browse the repository at this point in the history
(cherry picked from commit 1d0f938)
  • Loading branch information
mamil authored and Bisstocuz committed Nov 22, 2021
1 parent a2bf217 commit 719a7c0
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
2 changes: 1 addition & 1 deletion tree.go
Expand Up @@ -472,7 +472,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
}
Expand Down
13 changes: 13 additions & 0 deletions tree_test.go
Expand Up @@ -836,6 +836,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
Expand Down

0 comments on commit 719a7c0

Please sign in to comment.