diff --git a/pkg/proc/eval.go b/pkg/proc/eval.go index 42a30f3f..296905f7 100644 --- a/pkg/proc/eval.go +++ b/pkg/proc/eval.go @@ -1041,10 +1041,16 @@ func (scope *EvalScope) evalStructSelector(node *ast.SelectorExpr) (*Variable, e if err != nil { return nil, err } + // Prevent abuse, attempting to call "nil.member" directly. if xv.Addr == 0 && xv.Name == "nil" { return nil, fmt.Errorf("%s (type %s) is not a struct", xv.Name, xv.TypeString()) } + // Prevent abuse, attempting to call "\"fake\".member" directly. + if xv.Addr == 0 && xv.Name == "" && xv.DwarfType == nil && xv.RealType == nil { + return nil, fmt.Errorf("%s (type %s) is not a struct", xv.Value, xv.TypeString()) + } + rv, err := xv.findMethod(node.Sel.Name) if err != nil { return nil, err diff --git a/service/test/variables_test.go b/service/test/variables_test.go index 78cdf220..e69aacfb 100644 --- a/service/test/variables_test.go +++ b/service/test/variables_test.go @@ -1205,6 +1205,8 @@ func TestCallFunction(t *testing.T) { {"x.CallMe()", nil, nil}, {"x2.CallMe(5)", []string{":int:25"}, nil}, + {"\"delve\".CallMe()", nil, errors.New("\"delve\" (type string) is not a struct")}, + // Nested function calls tests {`onetwothree(intcallpanic(2))`, []string{`:[]int:[]int len: 3, cap: 3, [3,4,5]`}, nil},