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:
parent
ad75f78c4e
commit
65d7f5c65f
@ -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},
|
||||
|
Loading…
Reference in New Issue
Block a user