From 1544791dc0650c4fd4520fab7fcab3cea39f6ee5 Mon Sep 17 00:00:00 2001 From: raymonder jin Date: Fri, 25 Jun 2021 13:22:01 +0800 Subject: [PATCH] Fix insufficient slice check (#2755) --- tree.go | 2 +- tree_test.go | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/tree.go b/tree.go index d18ef5dd..acc9cbd6 100644 --- a/tree.go +++ b/tree.go @@ -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 } diff --git a/tree_test.go b/tree_test.go index d799e45a..ea13c30e 100644 --- a/tree_test.go +++ b/tree_test.go @@ -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", ¶ms, false) +} + func TestTreeWildcardConflictEx(t *testing.T) { conflicts := [...]struct { route string