Skip to content

Commit

Permalink
proc: check recursion level when loading pointers (#3431)
Browse files Browse the repository at this point in the history
Fixes #3429
  • Loading branch information
aarzilli committed Jul 7, 2023
1 parent 71f1220 commit c1482ca
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
5 changes: 5 additions & 0 deletions _fixtures/testvariables2.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,8 @@ type ThreeInts struct {

var _ I = (*W2)(nil)

type pptr *pptr

func main() {
i1 := 1
i2 := 2
Expand Down Expand Up @@ -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++ {
Expand Down
13 changes: 12 additions & 1 deletion pkg/proc/variables.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
2 changes: 2 additions & 0 deletions pkg/proc/variables_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down

0 comments on commit c1482ca

Please sign in to comment.