mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-01-18 21:35:24 +01:00
routing: fix memory corruption in MC store
Since bbolt returns references to internally stored data when storing locally it's best to copy the byte slices returned or alternatively convert them to string (which also makes a copy) to avoid crashes casued by memory corruption.
This commit is contained in:
parent
71b23a2c54
commit
8cd607447e
@ -82,7 +82,7 @@ func newMissionControlStore(db kvdb.Backend, maxRecords int,
|
||||
// difference when updating the DB state.
|
||||
c := resultsBucket.ReadCursor()
|
||||
for k, _ := c.First(); k != nil; k, _ = c.Next() {
|
||||
keys.PushBack(k)
|
||||
keys.PushBack(string(k))
|
||||
keysMap[string(k)] = struct{}{}
|
||||
}
|
||||
|
||||
@ -334,7 +334,7 @@ func (b *missionControlStore) storeResults() error {
|
||||
return err
|
||||
}
|
||||
|
||||
keys.PushBack(k)
|
||||
keys.PushBack(string(k))
|
||||
keysMap[string(k)] = struct{}{}
|
||||
}
|
||||
|
||||
@ -345,14 +345,14 @@ func (b *missionControlStore) storeResults() error {
|
||||
}
|
||||
|
||||
front := keys.Front()
|
||||
key := front.Value.([]byte)
|
||||
key := front.Value.(string)
|
||||
|
||||
if err := bucket.Delete(key); err != nil {
|
||||
if err := bucket.Delete([]byte(key)); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
keys.Remove(front)
|
||||
delete(keysMap, string(key))
|
||||
delete(keysMap, key)
|
||||
}
|
||||
|
||||
return nil
|
||||
|
Loading…
Reference in New Issue
Block a user