mirror of
https://github.com/gin-gonic/gin.git
synced 2026-09-04 22:53:34 +08:00
fix: reset skipped-nodes stack on getValue entry to prevent slice overflow panic [#4818]
This commit is contained in:
parent
dcaa4296d1
commit
5cf02b6f7f
8
tree.go
8
tree.go
@ -418,6 +418,14 @@ type skippedNode struct {
|
|||||||
func (n *node) getValue(path string, params *Params, skippedNodes *[]skippedNode, unescape bool) (value nodeValue) {
|
func (n *node) getValue(path string, params *Params, skippedNodes *[]skippedNode, unescape bool) (value nodeValue) {
|
||||||
var globalParamsCount int16
|
var globalParamsCount int16
|
||||||
|
|
||||||
|
// Reset the skipped-nodes stack on entry. getValue is called once per
|
||||||
|
// method tree (e.g. in the HandleMethodNotAllowed loop) reusing the same
|
||||||
|
// pooled Context stack, and the walk below grows it via a raw reslice that
|
||||||
|
// cannot exceed engine.maxSections. Without this reset the residue from a
|
||||||
|
// previous tree leaks into the next call and can panic with "slice bounds
|
||||||
|
// out of range" once the accumulated length passes the capacity.
|
||||||
|
*skippedNodes = (*skippedNodes)[:0]
|
||||||
|
|
||||||
walk: // Outer loop for walking the tree
|
walk: // Outer loop for walking the tree
|
||||||
for {
|
for {
|
||||||
prefix := n.path
|
prefix := n.path
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user