pkg/proc: Prevent program crash when called meanless expression (#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: #1871
This commit is contained in:
chainhelen 2020-03-18 11:26:24 -05:00 committed by GitHub
parent ad75f78c4e
commit 65d7f5c65f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 0 deletions

@ -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

@ -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},