From 125ccfc6efbd7ff830a5441c0fb6a0fd27790ac0 Mon Sep 17 00:00:00 2001 From: "Luke I. Wilson" Date: Thu, 9 Jun 2022 21:30:47 -0500 Subject: [PATCH] Prevent slice out of bounds access before panic Previously, when the error would be triggered, it was possible that a slice out of bounds panic would occur before the intended panic message. I've added a nil/slice length check to make sure that does not happen. With that said, I am not very familiar with the library so I cannot determine what this catch was supposed to mean, or convey, to users of the library. It would be helpful to know what I can do to make the error message more useful. Thanks. Fixes #3126 --- tree.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/tree.go b/tree.go index 88100eec..030617ee 100644 --- a/tree.go +++ b/tree.go @@ -349,7 +349,11 @@ func (n *node) insertChild(path string, fullPath string, handlers HandlersChain) } if len(n.path) > 0 && n.path[len(n.path)-1] == '/' { - pathSeg := strings.SplitN(n.children[0].path, "/", 2)[0] + // Wildcard conflict + pathSeg := path + if len(n.children) != 0 { + pathSeg = strings.SplitN(n.children[0].path, "/", 2)[0] + } panic("catch-all wildcard '" + path + "' in new path '" + fullPath + "' conflicts with existing path segment '" + pathSeg +