Merge pull request #1404 from filecoin-project/asr/segfault

Bugfix: Check if vmctx is nil before dereferencing in ApplyMessage
This commit is contained in:
Whyrusleeping 2020-03-11 13:29:33 -07:00 committed by GitHub
commit 954085d33e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -44,9 +44,9 @@ const (
) )
type ExecutionResult struct { type ExecutionResult struct {
Msg *types.Message Msg *types.Message
MsgRct *types.MessageReceipt MsgRct *types.MessageReceipt
Error string Error string
} }
type VMContext struct { type VMContext struct {
@ -173,9 +173,9 @@ func (vmc *VMContext) Send(to address.Address, method uint64, value types.BigInt
es = err.Error() es = err.Error()
} }
er := ExecutionResult{ er := ExecutionResult{
Msg: msg, Msg: msg,
MsgRct: &mr, MsgRct: &mr,
Error: es, Error: es,
} }
vmc.internalExecutions = append(vmc.internalExecutions, &er) vmc.internalExecutions = append(vmc.internalExecutions, &er)
@ -366,7 +366,7 @@ type Rand interface {
type ApplyRet struct { type ApplyRet struct {
types.MessageReceipt types.MessageReceipt
ActorErr aerrors.ActorError ActorErr aerrors.ActorError
InternalExecutions []*ExecutionResult InternalExecutions []*ExecutionResult
} }
@ -532,15 +532,21 @@ func (vm *VM) ApplyMessage(ctx context.Context, msg *types.Message) (*ApplyRet,
return nil, xerrors.Errorf("gas handling math is wrong") return nil, xerrors.Errorf("gas handling math is wrong")
} }
return &ApplyRet{ r := ApplyRet{
MessageReceipt: types.MessageReceipt{ MessageReceipt: types.MessageReceipt{
ExitCode: errcode, ExitCode: errcode,
Return: ret, Return: ret,
GasUsed: gasUsed, GasUsed: gasUsed,
}, },
ActorErr: actorErr, ActorErr: actorErr,
InternalExecutions: vmctx.internalExecutions, InternalExecutions: nil,
}, nil }
if vmctx != nil {
r.InternalExecutions = vmctx.internalExecutions
}
return &r, nil
} }
func (vm *VM) SetBlockMiner(m address.Address) { func (vm *VM) SetBlockMiner(m address.Address) {