Merge pull request #363 from filecoin-project/feat/no-empty-addr

prevent serialization of empty addresses
This commit is contained in:
Łukasz Magiera 2019-10-15 02:04:23 +02:00 committed by GitHub
commit 67c7dc46ee
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 26 additions and 9 deletions

View File

@ -65,7 +65,7 @@ func TestVMInvokeMethod(t *testing.T) {
from := addrs[0] from := addrs[0]
var err error var err error
cenc, err := SerializeParams(&StorageMinerConstructorParams{}) cenc, err := SerializeParams(&StorageMinerConstructorParams{Owner: from, Worker: from})
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -116,6 +116,7 @@ func TestStorageMarketActorCreateMiner(t *testing.T) {
cheatStorageMarketTotal(t, vm, bs) cheatStorageMarketTotal(t, vm, bs)
params := &StorageMinerConstructorParams{ params := &StorageMinerConstructorParams{
Owner: maddr,
Worker: maddr, Worker: maddr,
SectorSize: types.NewInt(build.SectorSize), SectorSize: types.NewInt(build.SectorSize),
PeerID: "fakepeerid", PeerID: "fakepeerid",

View File

@ -325,6 +325,10 @@ func hash(ingest []byte, cfg *blake2b.Config) []byte {
} }
func (a Address) MarshalCBOR(w io.Writer) error { func (a Address) MarshalCBOR(w io.Writer) error {
if a == Undef {
return fmt.Errorf("cannot marshal undefined address")
}
abytes := a.Bytes() abytes := a.Bytes()
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajByteString, uint64(len(abytes)))); err != nil { if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajByteString, uint64(len(abytes)))); err != nil {
return err return err
@ -360,6 +364,9 @@ func (a *Address) UnmarshalCBOR(br io.Reader) error {
if err != nil { if err != nil {
return err return err
} }
if addr == Undef {
return fmt.Errorf("cbor input should not contain empty addresses")
}
*a = addr *a = addr

View File

@ -45,9 +45,11 @@ func (fcs *fakeCS) ChainGetTipSetByHeight(context.Context, uint64, *types.TipSet
} }
func makeTs(t *testing.T, h uint64, msgcid cid.Cid) *types.TipSet { func makeTs(t *testing.T, h uint64, msgcid cid.Cid) *types.TipSet {
a, _ := address.NewFromString("t00")
ts, err := types.NewTipSet([]*types.BlockHeader{ ts, err := types.NewTipSet([]*types.BlockHeader{
{ {
Height: h, Height: h,
Miner: a,
ParentStateRoot: dummyCid, ParentStateRoot: dummyCid,
Messages: msgcid, Messages: msgcid,
@ -479,7 +481,7 @@ func TestCalled(t *testing.T) {
fcs.advance(0, 3, map[int]cid.Cid{ // msg at H=6; H=8 (confidence=2) fcs.advance(0, 3, map[int]cid.Cid{ // msg at H=6; H=8 (confidence=2)
0: fcs.fakeMsgs(fakeMsg{ 0: fcs.fakeMsgs(fakeMsg{
bmsgs: []*types.Message{ bmsgs: []*types.Message{
{To: t0123, Method: 5, Nonce: 1}, {To: t0123, From: t0123, Method: 5, Nonce: 1},
}, },
}), }),
}) })
@ -520,7 +522,7 @@ func TestCalled(t *testing.T) {
n2msg := fcs.fakeMsgs(fakeMsg{ n2msg := fcs.fakeMsgs(fakeMsg{
bmsgs: []*types.Message{ bmsgs: []*types.Message{
{To: t0123, Method: 5, Nonce: 2}, {To: t0123, From: t0123, Method: 5, Nonce: 2},
}, },
}) })
@ -574,7 +576,7 @@ func TestCalled(t *testing.T) {
fcs.advance(0, 1, map[int]cid.Cid{ // msg at H=16; H=16 fcs.advance(0, 1, map[int]cid.Cid{ // msg at H=16; H=16
0: fcs.fakeMsgs(fakeMsg{ 0: fcs.fakeMsgs(fakeMsg{
bmsgs: []*types.Message{ bmsgs: []*types.Message{
{To: t0123, Method: 5, Nonce: 3}, {To: t0123, From: t0123, Method: 5, Nonce: 3},
}, },
}), }),
}) })
@ -597,7 +599,7 @@ func TestCalled(t *testing.T) {
fcs.advance(0, 4, map[int]cid.Cid{ // msg at H=26; H=29 fcs.advance(0, 4, map[int]cid.Cid{ // msg at H=26; H=29
0: fcs.fakeMsgs(fakeMsg{ 0: fcs.fakeMsgs(fakeMsg{
bmsgs: []*types.Message{ bmsgs: []*types.Message{
{To: t0123, Method: 5, Nonce: 4}, // this signals we don't want more {To: t0123, From: t0123, Method: 5, Nonce: 4}, // this signals we don't want more
}, },
}), }),
}) })
@ -609,7 +611,7 @@ func TestCalled(t *testing.T) {
fcs.advance(0, 4, map[int]cid.Cid{ // msg at H=26; H=29 fcs.advance(0, 4, map[int]cid.Cid{ // msg at H=26; H=29
0: fcs.fakeMsgs(fakeMsg{ 0: fcs.fakeMsgs(fakeMsg{
bmsgs: []*types.Message{ bmsgs: []*types.Message{
{To: t0123, Method: 5, Nonce: 5}, {To: t0123, From: t0123, Method: 5, Nonce: 5},
}, },
}), }),
}) })
@ -754,12 +756,12 @@ func TestCalledOrder(t *testing.T) {
fcs.advance(0, 10, map[int]cid.Cid{ fcs.advance(0, 10, map[int]cid.Cid{
1: fcs.fakeMsgs(fakeMsg{ 1: fcs.fakeMsgs(fakeMsg{
bmsgs: []*types.Message{ bmsgs: []*types.Message{
{To: t0123, Method: 5, Nonce: 1}, {To: t0123, From: t0123, Method: 5, Nonce: 1},
}, },
}), }),
2: fcs.fakeMsgs(fakeMsg{ 2: fcs.fakeMsgs(fakeMsg{
bmsgs: []*types.Message{ bmsgs: []*types.Message{
{To: t0123, Method: 5, Nonce: 2}, {To: t0123, From: t0123, Method: 5, Nonce: 2},
}, },
}), }),
}) })

View File

@ -2,9 +2,11 @@ package events
import ( import (
"context" "context"
"github.com/stretchr/testify/require"
"testing" "testing"
"github.com/stretchr/testify/require"
"github.com/filecoin-project/go-lotus/chain/address"
"github.com/filecoin-project/go-lotus/chain/types" "github.com/filecoin-project/go-lotus/chain/types"
) )
@ -16,8 +18,11 @@ func TestTsCache(t *testing.T) {
h := uint64(75) h := uint64(75)
a, _ := address.NewFromString("t00")
add := func() { add := func() {
ts, err := types.NewTipSet([]*types.BlockHeader{{ ts, err := types.NewTipSet([]*types.BlockHeader{{
Miner: a,
Height: h, Height: h,
ParentStateRoot: dummyCid, ParentStateRoot: dummyCid,
Messages: dummyCid, Messages: dummyCid,
@ -54,8 +59,10 @@ func TestTsCacheNulls(t *testing.T) {
h := uint64(75) h := uint64(75)
a, _ := address.NewFromString("t00")
add := func() { add := func() {
ts, err := types.NewTipSet([]*types.BlockHeader{{ ts, err := types.NewTipSet([]*types.BlockHeader{{
Miner: a,
Height: h, Height: h,
ParentStateRoot: dummyCid, ParentStateRoot: dummyCid,
Messages: dummyCid, Messages: dummyCid,