diff options
author | Felix Lange <fjl@twurst.com> | 2015-05-14 03:29:32 +0800 |
---|---|---|
committer | Felix Lange <fjl@twurst.com> | 2015-05-14 03:49:04 +0800 |
commit | 251846d65a87ed1c4a880e25622b09284eff873d (patch) | |
tree | d7d178637d70dec323803197a8701ba1ebd10bbe /p2p/discover/udp_test.go | |
parent | b2119d8931b054fe85cd80c02a5c9db033f61ab3 (diff) | |
download | go-tangerine-251846d65a87ed1c4a880e25622b09284eff873d.tar go-tangerine-251846d65a87ed1c4a880e25622b09284eff873d.tar.gz go-tangerine-251846d65a87ed1c4a880e25622b09284eff873d.tar.bz2 go-tangerine-251846d65a87ed1c4a880e25622b09284eff873d.tar.lz go-tangerine-251846d65a87ed1c4a880e25622b09284eff873d.tar.xz go-tangerine-251846d65a87ed1c4a880e25622b09284eff873d.tar.zst go-tangerine-251846d65a87ed1c4a880e25622b09284eff873d.zip |
p2p/discover: fix out-of-bounds slicing for chunked neighbors packets
The code assumed that Table.closest always returns at least 13 nodes.
This is not true for small tables (e.g. during bootstrap).
Diffstat (limited to 'p2p/discover/udp_test.go')
-rw-r--r-- | p2p/discover/udp_test.go | 31 |
1 files changed, 13 insertions, 18 deletions
diff --git a/p2p/discover/udp_test.go b/p2p/discover/udp_test.go index 7bf6df5ab..11fa31d7c 100644 --- a/p2p/discover/udp_test.go +++ b/p2p/discover/udp_test.go @@ -164,26 +164,21 @@ func TestUDP_findnode(t *testing.T) { // check that closest neighbors are returned. test.packetIn(nil, findnodePacket, &findnode{Target: testTarget, Expiration: futureExp}) expected := test.table.closest(targetHash, bucketSize) - test.waitPacketOut(func(p *neighbors) { - if len(p.Nodes) != 13 { - t.Errorf("wrong number of results: got %d, want %d", len(p.Nodes), bucketSize) - } - for i := range p.Nodes { - if p.Nodes[i].ID != expected.entries[i].ID { - t.Errorf("result mismatch at %d:\n got: %v\n want: %v", i, p.Nodes[i], expected.entries[i]) + + waitNeighbors := func(want []*Node) { + test.waitPacketOut(func(p *neighbors) { + if len(p.Nodes) != len(want) { + t.Errorf("wrong number of results: got %d, want %d", len(p.Nodes), bucketSize) } - } - }) - test.waitPacketOut(func(p *neighbors) { - if len(p.Nodes) != 3 { - t.Errorf("wrong number of results: got %d, want %d", len(p.Nodes), bucketSize) - } - for i := range p.Nodes { - if p.Nodes[i].ID != expected.entries[i + 13].ID { - t.Errorf("result mismatch at %d:\n got: %v\n want: %v", i, p.Nodes[i], expected.entries[i]) + for i := range p.Nodes { + if p.Nodes[i].ID != want[i].ID { + t.Errorf("result mismatch at %d:\n got: %v\n want: %v", i, p.Nodes[i], expected.entries[i]) + } } - } - }) + }) + } + waitNeighbors(expected.entries[:maxNeighbors]) + waitNeighbors(expected.entries[maxNeighbors:]) } func TestUDP_findnodeMultiReply(t *testing.T) { |