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

当key不存在时zset的部分接口会导致进程panic #99

Open
rocket323 opened this issue Sep 29, 2016 · 0 comments
Open

当key不存在时zset的部分接口会导致进程panic #99

rocket323 opened this issue Sep 29, 2016 · 0 comments

Comments

@rocket323
Copy link

rocket323 commented Sep 29, 2016

问题涉及到的zset接口:ZCount, ZLexCount, ZRange, ZRevRange, ZRangeByLex, ZRevRangeByLex, ZRangeByScore, ZRevRangeByScore.

以ZCount为例:

o, err := s.loadZSetRow(db, key)
if err != nil {
    return 0, errors.Trace(err)
}

var count int64 = 0
f := func(o *zsetRow) error {
    count++
    return nil
}

if err = o.travelInRange(s, r, f); err != nil {
    return 0, errors.Trace(err)
}

s.loadZSetRow方法在zset集合key不存在的情况下,可能会err != nil 并且 o == nil,而代码只判断了err是否为nil,没有判断o为nil的情况。后面调用o的方法的时候就panic了。

if err != nil || o == nil {
    return 0, errors.Trace(err)
}

改成上面这样可以解决问题,其他的接口也同样修改,麻烦看下:)

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

No branches or pull requests

1 participant