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

Check store keys length before accessing them #8451

Closed
4 tasks
amaury1093 opened this issue Jan 27, 2021 · 0 comments · Fixed by #9639
Closed
4 tasks

Check store keys length before accessing them #8451

amaury1093 opened this issue Jan 27, 2021 · 0 comments · Fixed by #9639
Assignees
Labels
C:Store Type: Code Hygiene General cleanup and restructuring of code to provide clarity, flexibility, and modularity.

Comments

@amaury1093
Copy link
Contributor

amaury1093 commented Jan 27, 2021

Summary of Bug

Before accessing a store key (e.g. a := key[n:m]), we should make that sure key is at least of length m+1.

ref: #8363 (comment)

Version

v0.41.0

Proposal

func assertKeyAtLeastLength(bz []byte, length int) {
  if len(bz) < length {
    panic(fmt.Sprintf("expected key of length at least %d, got %d", length, len(bz)))
  }
}

// in module's keys.go
assertKeyAtLeastLength(key, 2)
addrLen := key[1]
// repeat assert-access steps everywhere

Pros

  • Better error message

Cons

  • Slightly longer code.

For Admin Use

  • Not duplicate issue
  • Appropriate labels applied
  • Appropriate contributors tagged
  • Contributor assigned/self-assigned
@amaury1093 amaury1093 added Type: Code Hygiene General cleanup and restructuring of code to provide clarity, flexibility, and modularity. C:Store labels Jan 27, 2021
@likhita-809 likhita-809 self-assigned this Jul 5, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C:Store Type: Code Hygiene General cleanup and restructuring of code to provide clarity, flexibility, and modularity.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants