Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
p2p
go-p2p-kad-dht
Commits
d03fffba
Commit
d03fffba
authored
Sep 13, 2016
by
Jeromy
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
dht: protect against a panic in case record on pbmessage is nil
From ipfs/go-ipfs#8f362d2b1500809cbae2ee08c2b42a6f226a10b8
parent
02dc9400
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
25 additions
and
3 deletions
+25
-3
dht_test.go
dht_test.go
+14
-0
handlers.go
handlers.go
+7
-3
records.go
records.go
+4
-0
No files found.
dht_test.go
View file @
d03fffba
...
@@ -9,6 +9,8 @@ import (
...
@@ -9,6 +9,8 @@ import (
"testing"
"testing"
"time"
"time"
pb
"github.com/libp2p/go-libp2p-kad-dht/pb"
ds
"github.com/ipfs/go-datastore"
ds
"github.com/ipfs/go-datastore"
dssync
"github.com/ipfs/go-datastore/sync"
dssync
"github.com/ipfs/go-datastore/sync"
u
"github.com/ipfs/go-ipfs-util"
u
"github.com/ipfs/go-ipfs-util"
...
@@ -825,3 +827,15 @@ func TestConnectCollision(t *testing.T) {
...
@@ -825,3 +827,15 @@ func TestConnectCollision(t *testing.T) {
dhtB
.
host
.
Close
()
dhtB
.
host
.
Close
()
}
}
}
}
func
TestBadProtoMessages
(
t
*
testing
.
T
)
{
ctx
,
cancel
:=
context
.
WithCancel
(
context
.
Background
())
defer
cancel
()
d
:=
setupDHT
(
ctx
,
t
)
nilrec
:=
new
(
pb
.
Message
)
if
_
,
err
:=
d
.
handlePutValue
(
ctx
,
"testpeer"
,
nilrec
);
err
==
nil
{
t
.
Fatal
(
"should have errored on nil record"
)
}
}
handlers.go
View file @
d03fffba
...
@@ -150,13 +150,17 @@ func (dht *IpfsDHT) handlePutValue(ctx context.Context, p peer.ID, pmes *pb.Mess
...
@@ -150,13 +150,17 @@ func (dht *IpfsDHT) handlePutValue(ctx context.Context, p peer.ID, pmes *pb.Mess
defer
log
.
EventBegin
(
ctx
,
"handlePutValue"
,
p
)
.
Done
()
defer
log
.
EventBegin
(
ctx
,
"handlePutValue"
,
p
)
.
Done
()
dskey
:=
key
.
Key
(
pmes
.
GetKey
())
.
DsKey
()
dskey
:=
key
.
Key
(
pmes
.
GetKey
())
.
DsKey
()
if
err
:=
dht
.
verifyRecordLocally
(
pmes
.
GetRecord
());
err
!=
nil
{
rec
:=
pmes
.
GetRecord
()
if
rec
==
nil
{
log
.
Infof
(
"Got nil record from: %s"
,
p
.
Pretty
())
return
nil
,
errors
.
New
(
"nil record"
)
}
if
err
:=
dht
.
verifyRecordLocally
(
rec
);
err
!=
nil
{
log
.
Warningf
(
"Bad dht record in PUT from: %s. %s"
,
key
.
Key
(
pmes
.
GetRecord
()
.
GetAuthor
()),
err
)
log
.
Warningf
(
"Bad dht record in PUT from: %s. %s"
,
key
.
Key
(
pmes
.
GetRecord
()
.
GetAuthor
()),
err
)
return
nil
,
err
return
nil
,
err
}
}
rec
:=
pmes
.
GetRecord
()
// record the time we receive every record
// record the time we receive every record
rec
.
TimeReceived
=
proto
.
String
(
u
.
FormatRFC3339
(
time
.
Now
()))
rec
.
TimeReceived
=
proto
.
String
(
u
.
FormatRFC3339
(
time
.
Now
()))
...
...
records.go
View file @
d03fffba
...
@@ -107,6 +107,10 @@ func (dht *IpfsDHT) getPublicKeyFromNode(ctx context.Context, p peer.ID) (ci.Pub
...
@@ -107,6 +107,10 @@ func (dht *IpfsDHT) getPublicKeyFromNode(ctx context.Context, p peer.ID) (ci.Pub
// verifyRecordLocally attempts to verify a record. if we do not have the public
// verifyRecordLocally attempts to verify a record. if we do not have the public
// key, we fail. we do not search the dht.
// key, we fail. we do not search the dht.
func
(
dht
*
IpfsDHT
)
verifyRecordLocally
(
r
*
recpb
.
Record
)
error
{
func
(
dht
*
IpfsDHT
)
verifyRecordLocally
(
r
*
recpb
.
Record
)
error
{
if
r
==
nil
{
log
.
Error
(
"nil record passed into verifyRecordLocally"
)
return
fmt
.
Errorf
(
"nil record"
)
}
if
len
(
r
.
Signature
)
>
0
{
if
len
(
r
.
Signature
)
>
0
{
// First, validate the signature
// First, validate the signature
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment