Commit 52064084 authored by Juan Batiz-Benet's avatar Juan Batiz-Benet Committed by Brian Tiger Chow

check type assertion

`v.([]byte)` coming from a datastore can panic.
`byt, ok := v.([]byte)` to be safe.

@whyrusleeping
parent 0fca9868
......@@ -280,7 +280,12 @@ func (dht *IpfsDHT) getLocal(key u.Key) ([]byte, error) {
if err != nil {
return nil, err
}
return v.([]byte), nil
byt, ok := v.([]byte)
if !ok {
return byt, errors.New("value stored in datastore not []byte")
}
return byt, nil
}
func (dht *IpfsDHT) putLocal(key u.Key, value []byte) error {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment