lib/protocol: Avoid panic in DeviceIDFromBytes (#6714)
This commit is contained in:
+5
-1
@@ -264,7 +264,11 @@ func TestUpdate0to3(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if !ok {
|
||||
t.Fatal("surprise missing global file", string(name), protocol.DeviceIDFromBytes(vl.Versions[0].Device))
|
||||
device := "<invalid>"
|
||||
if dev, err := protocol.DeviceIDFromBytes(vl.Versions[0].Device); err != nil {
|
||||
device = dev.String()
|
||||
}
|
||||
t.Fatal("surprise missing global file", string(name), device)
|
||||
}
|
||||
e, ok := need[fi.FileName()]
|
||||
if !ok {
|
||||
|
||||
+4
-1
@@ -121,7 +121,10 @@ func (db *Lowlevel) updateRemoteFiles(folder, device []byte, fs []protocol.FileI
|
||||
defer t.close()
|
||||
|
||||
var dk, gk, keyBuf []byte
|
||||
devID := protocol.DeviceIDFromBytes(device)
|
||||
devID, err := protocol.DeviceIDFromBytes(device)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
for _, f := range fs {
|
||||
name := []byte(f.Name)
|
||||
dk, err = db.keyer.GenerateDeviceFileKey(dk, folder, device, name)
|
||||
|
||||
+9
-2
@@ -52,7 +52,11 @@ func (m *metadataTracker) Unmarshal(bs []byte) error {
|
||||
|
||||
// Initialize the index map
|
||||
for i, c := range m.counts.Counts {
|
||||
m.indexes[metaKey{protocol.DeviceIDFromBytes(c.DeviceID), c.LocalFlags}] = i
|
||||
dev, err := protocol.DeviceIDFromBytes(c.DeviceID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
m.indexes[metaKey{dev, c.LocalFlags}] = i
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -392,7 +396,10 @@ func (m *countsMap) devices() []protocol.DeviceID {
|
||||
|
||||
for _, dev := range m.counts.Counts {
|
||||
if dev.Sequence > 0 {
|
||||
id := protocol.DeviceIDFromBytes(dev.DeviceID)
|
||||
id, err := protocol.DeviceIDFromBytes(dev.DeviceID)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
if id == protocol.GlobalDeviceID || id == protocol.LocalDeviceID {
|
||||
continue
|
||||
}
|
||||
|
||||
+17
-4
@@ -414,7 +414,11 @@ func (t *readOnlyTransaction) availability(folder, file []byte) ([]protocol.Devi
|
||||
}
|
||||
devices := make([]protocol.DeviceID, len(fv.Devices))
|
||||
for i, dev := range fv.Devices {
|
||||
devices[i] = protocol.DeviceIDFromBytes(dev)
|
||||
n, err := protocol.DeviceIDFromBytes(dev)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
devices[i] = n
|
||||
}
|
||||
|
||||
return devices, nil
|
||||
@@ -436,7 +440,10 @@ func (t *readOnlyTransaction) withNeed(folder, device []byte, truncate bool, fn
|
||||
defer dbi.Release()
|
||||
|
||||
var dk []byte
|
||||
devID := protocol.DeviceIDFromBytes(device)
|
||||
devID, err := protocol.DeviceIDFromBytes(device)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
for dbi.Next() {
|
||||
var vl VersionList
|
||||
if err := vl.Unmarshal(dbi.Value()); err != nil {
|
||||
@@ -592,7 +599,10 @@ func (t readWriteTransaction) putFile(fkey []byte, fi protocol.FileInfo, truncat
|
||||
// file. If the device is already present in the list, the version is updated.
|
||||
// If the file does not have an entry in the global list, it is created.
|
||||
func (t readWriteTransaction) updateGlobal(gk, keyBuf, folder, device []byte, file protocol.FileInfo, meta *metadataTracker) ([]byte, bool, error) {
|
||||
deviceID := protocol.DeviceIDFromBytes(device)
|
||||
deviceID, err := protocol.DeviceIDFromBytes(device)
|
||||
if err != nil {
|
||||
return nil, false, err
|
||||
}
|
||||
|
||||
l.Debugf("update global; folder=%q device=%v file=%q version=%v invalid=%v", folder, deviceID, file.Name, file.Version, file.IsInvalid())
|
||||
|
||||
@@ -768,7 +778,10 @@ func need(global FileVersion, haveLocal bool, localVersion protocol.Vector) bool
|
||||
// given file. If the version list is empty after this, the file entry is
|
||||
// removed entirely.
|
||||
func (t readWriteTransaction) removeFromGlobal(gk, keyBuf, folder, device, file []byte, meta *metadataTracker) ([]byte, error) {
|
||||
deviceID := protocol.DeviceIDFromBytes(device)
|
||||
deviceID, err := protocol.DeviceIDFromBytes(device)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
l.Debugf("remove from global; folder=%q device=%v file=%q", folder, deviceID, file)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user