diff options
author | Brielle Broder <bbroder@google.com> | 2018-08-01 09:43:47 -0700 |
---|---|---|
committer | Shentubot <shentubot@google.com> | 2018-08-01 09:44:57 -0700 |
commit | 6b87378634e1575cf590b7558f19b40b012849c2 (patch) | |
tree | 14433da4615d2010a5d34ade91ff94b938c5a9b5 | |
parent | 413bfb39a940455cb116c7d0ca715b2ced78a11c (diff) |
New conditional for adding key/value pairs to maps.
When adding MultiDeviceKeys and their values into MultiDevice maps, make
sure the keys and values have not already been added. This ensures that
preexisting key/value pairs are not overridden.
PiperOrigin-RevId: 206942766
Change-Id: I9d85f38eb59ba59f0305e6614a52690608944981
-rw-r--r-- | pkg/sentry/device/device.go | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/pkg/sentry/device/device.go b/pkg/sentry/device/device.go index a5514c72f..21fee8f8a 100644 --- a/pkg/sentry/device/device.go +++ b/pkg/sentry/device/device.go @@ -183,6 +183,14 @@ func (m *MultiDevice) Load(key MultiDeviceKey, value uint64) bool { m.rcache = make(map[uint64]MultiDeviceKey) } + if val, exists := m.cache[key]; exists && val != value { + return false + } + if k, exists := m.rcache[value]; exists && k != key { + // Should never happen. + panic("MultiDevice's caches are inconsistent") + } + // Cache value at key. m.cache[key] = value |