proc: check recursion level when loading pointers (#3431)

Fixes #3429
This commit is contained in:
Alessandro Arzilli 2023-07-07 19:32:05 +02:00 committed by GitHub
parent 71f1220717
commit c1482ca911
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 19 additions and 1 deletions

@ -151,6 +151,8 @@ type ThreeInts struct {
var _ I = (*W2)(nil)
type pptr *pptr
func main() {
i1 := 1
i2 := 2
@ -388,6 +390,9 @@ func main() {
int3chan <- ThreeInts{a: 2}
int3chan <- ThreeInts{a: 3}
var ptrinf2 pptr
ptrinf2 = &ptrinf2
var amb1 = 1
runtime.Breakpoint()
for amb1 := 0; amb1 < 10; amb1++ {

@ -1305,10 +1305,21 @@ func (v *Variable) loadValueInternal(recurseLevel int, cfg LoadConfig) {
// Don't increase the recursion level when dereferencing pointers
// unless this is a pointer to interface (which could cause an infinite loop)
nextLvl := recurseLevel
checkLvl := false
if v.Children[0].Kind == reflect.Interface {
nextLvl++
} else if ptyp, isptr := v.RealType.(*godwarf.PtrType); isptr {
_, elemTypIsPtr := resolveTypedef(ptyp.Type).(*godwarf.PtrType)
if elemTypIsPtr {
nextLvl++
checkLvl = true
}
}
if checkLvl && recurseLevel > cfg.MaxVariableRecurse {
v.Children[0].OnlyAddr = true
} else {
v.Children[0].loadValueInternal(nextLvl, cfg)
}
v.Children[0].loadValueInternal(nextLvl, cfg)
} else {
v.Children[0].OnlyAddr = true
}

@ -741,6 +741,8 @@ func getEvalExpressionTestCases() []varTest {
{"emptymap", false, `map[string]string []`, `map[string]string []`, "map[string]string", nil},
{"mnil", false, `map[string]main.astruct nil`, `map[string]main.astruct nil`, "map[string]main.astruct", nil},
{"ptrinf2", false, `**(main.pptr)(…`, `(main.pptr)(…`, "main.pptr", nil},
// conversions between string/[]byte/[]rune (issue #548)
{"runeslice", true, `[]int32 len: 4, cap: 4, [116,232,115,116]`, `[]int32 len: 4, cap: 4, [...]`, "[]int32", nil},
{"byteslice", true, `[]uint8 len: 5, cap: 5, [116,195,168,115,116]`, `[]uint8 len: 5, cap: 5, [...]`, "[]uint8", nil},