From 9c83866c72b0cf6114a6670d0d789c8ddd6542c4 Mon Sep 17 00:00:00 2001 From: Alessandro Arzilli Date: Tue, 18 Aug 2020 02:18:34 +0200 Subject: [PATCH] proc: limit iteration depth of (*G).UserCurrent (#2135) Limit the iteration depth of proc.(*G).UserCurrent so that it doesn't keep going forever if the stack trace is not valid. Fixes #2119 --- pkg/proc/variables.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/pkg/proc/variables.go b/pkg/proc/variables.go index f3891bfa..f98c13cc 100644 --- a/pkg/proc/variables.go +++ b/pkg/proc/variables.go @@ -35,6 +35,8 @@ const ( maxFramePrefetchSize = 1 * 1024 * 1024 // Maximum prefetch size for a stack frame maxMapBucketsFactor = 100 // Maximum numbers of map buckets to read for every requested map entry when loading variables through (*EvalScope).LocalVariables and (*EvalScope).FunctionArguments. + + maxGoroutineUserCurrentDepth = 30 // Maximum depth used by (*G).UserCurrent to search its location ) type floatSpecial uint8 @@ -487,7 +489,7 @@ func (g *G) UserCurrent() Location { if err != nil { return g.CurrentLoc } - for it.Next() { + for count := 0; it.Next() && count < maxGoroutineUserCurrentDepth; count++ { frame := it.Frame() if frame.Call.Fn != nil { name := frame.Call.Fn.Name