Skip to content

Commit

Permalink
pkg/proc: Prevent program crash when called meanless expression (go-d…
Browse files Browse the repository at this point in the history
…elve#1934)

If we call one expression which is the fake method of meanless
string, `delve` will panic. Strengthen the inspection of boundary
conditions when supporting function calls on non-struct types.

Update: go-delve#1871
  • Loading branch information
chainhelen committed Mar 18, 2020
1 parent ad75f78 commit 65d7f5c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
6 changes: 6 additions & 0 deletions pkg/proc/eval.go
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions service/test/variables_test.go
Expand Up @@ -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},
Expand Down

0 comments on commit 65d7f5c

Please sign in to comment.