Skip to content

Commit

Permalink
Do not allow nil values to be set in CacheKVStore (#2708)
Browse files Browse the repository at this point in the history
* Do not allow nil values to be set in CacheKVStore
  • Loading branch information
jaekwon committed Nov 7, 2018
1 parent 4f46a4c commit c7b3efd
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
3 changes: 2 additions & 1 deletion PENDING.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ IMPROVEMENTS
- \#2660 [x/mock/simulation] Staking transactions get tested far more frequently
- \#2610 [x/stake] Block redelegation to and from the same validator
- \#2652 [x/auth] Add benchmark for get and set account
- \#2685 [x/store] Add general merkle absence proof (also for empty substores)
- \#2685 [store] Add general merkle absence proof (also for empty substores)
- \#2708 [store] Disallow setting nil values

* Tendermint

Expand Down
7 changes: 7 additions & 0 deletions store/cachekvstore.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ func (ci *cacheKVStore) Set(key []byte, value []byte) {
ci.mtx.Lock()
defer ci.mtx.Unlock()
ci.assertValidKey(key)
ci.assertValidValue(value)

ci.setCacheValue(key, value, false, true)
}
Expand Down Expand Up @@ -196,6 +197,12 @@ func (ci *cacheKVStore) assertValidKey(key []byte) {
}
}

func (ci *cacheKVStore) assertValidValue(value []byte) {
if value == nil {
panic("value is nil")
}
}

// Only entrypoint to mutate ci.cache.
func (ci *cacheKVStore) setCacheValue(key, value []byte, deleted bool, dirty bool) {
ci.cache[string(key)] = cValue{
Expand Down
2 changes: 1 addition & 1 deletion types/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ type KVStore interface {
// Has checks if a key exists. Panics on nil key.
Has(key []byte) bool

// Set sets the key. Panics on nil key.
// Set sets the key. Panics on nil key or value.
Set(key, value []byte)

// Delete deletes the key. Panics on nil key.
Expand Down

0 comments on commit c7b3efd

Please sign in to comment.