lib/protocol: Avoid panic in DeviceIDFromBytes (#6714)

This commit is contained in:
André Colomb
2020-06-07 10:31:12 +02:00
committed by GitHub
parent 607bcc0b0e
commit 46536509d7
9 changed files with 69 additions and 21 deletions
+9 -5
View File
@@ -73,12 +73,16 @@ func dump(ldb backend.Backend) {
case db.KeyTypeDeviceIdx:
key := binary.BigEndian.Uint32(key[1:])
val := it.Value()
if len(val) == 0 {
fmt.Printf("[deviceidx] K:%d V:<nil>\n", key)
} else {
dev := protocol.DeviceIDFromBytes(val)
fmt.Printf("[deviceidx] K:%d V:%s\n", key, dev)
device := "<nil>"
if len(val) > 0 {
dev, err := protocol.DeviceIDFromBytes(val)
if err != nil {
device = fmt.Sprintf("<invalid %d bytes>", len(val))
} else {
device = dev.String()
}
}
fmt.Printf("[deviceidx] K:%d V:%s\n", key, device)
case db.KeyTypeIndexID:
device := binary.BigEndian.Uint32(key[1:])