Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not allow nil values to be set in CacheKVStore #2708

Merged
merged 2 commits into from
Nov 7, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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