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

PrefixEndBytes() should return when len(prefix) == 0 #3727

Closed
mossid opened this issue Feb 25, 2019 · 1 comment
Closed

PrefixEndBytes() should return when len(prefix) == 0 #3727

mossid opened this issue Feb 25, 2019 · 1 comment

Comments

@mossid
Copy link
Contributor

mossid commented Feb 25, 2019

In https://github.com/cosmos/cosmos-sdk/blob/develop/store/types/utils.go#L61

        if prefix == nil {
		return nil
	}

        //...
	
	for {
		if end[len(end)-1] != byte(255) {
			end[len(end)-1]++
                        break
                }
                //...
        }

In the for loop, we access on the slice without checking the length. When the provided argument has length 0 but not nil([]byte{}), it throws a runtime error index out of range. We have to replace the conditional expression to len(prefix) == 0 from the current prefix == nil.

@alexanderbez
Copy link
Contributor

Indeed we should always be checking length on these slices in almost all cases.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants