mirror of https://github.com/redis/redis.git
Add tests to cover EXPIRE overflow fix (#9839)
In #8287, some overflow checks have been added. But when `when *= 1000` overflows, it will become a positive number. And the check not able to catch it. The key will be added with a short expiration time and will deleted a few seconds later. In #9601, will check the overflow after `*=` and return an error first, and avoiding this situation. In this commit, added some tests to cover those code paths. Found it in #9825, and close it.
This commit is contained in:
parent
a3a014294f
commit
9273d09dd4
|
|
@ -268,9 +268,17 @@ start_server {tags {"expire"}} {
|
|||
|
||||
test {EXPIRE with big integer overflows when converted to milliseconds} {
|
||||
r set foo bar
|
||||
catch {r EXPIRE foo 10000000000000000} e
|
||||
set e
|
||||
} {ERR invalid expire time in expire}
|
||||
|
||||
# Hit `when > LLONG_MAX - basetime`
|
||||
assert_error "ERR invalid expire time in expire" {r EXPIRE foo 9223370399119966}
|
||||
|
||||
# Hit `when > LLONG_MAX / 1000`
|
||||
assert_error "ERR invalid expire time in expire" {r EXPIRE foo 9223372036854776}
|
||||
assert_error "ERR invalid expire time in expire" {r EXPIRE foo 10000000000000000}
|
||||
assert_error "ERR invalid expire time in expire" {r EXPIRE foo 18446744073709561}
|
||||
|
||||
assert_equal {-1} [r ttl foo]
|
||||
}
|
||||
|
||||
test {PEXPIRE with big integer overflow when basetime is added} {
|
||||
r set foo bar
|
||||
|
|
@ -280,8 +288,11 @@ start_server {tags {"expire"}} {
|
|||
|
||||
test {EXPIRE with big negative integer} {
|
||||
r set foo bar
|
||||
catch {r EXPIRE foo -9999999999999999} e
|
||||
assert_match {ERR invalid expire time in expire} $e
|
||||
|
||||
# Hit `when < LLONG_MIN / 1000`
|
||||
assert_error "ERR invalid expire time in expire" {r EXPIRE foo -9223372036854776}
|
||||
assert_error "ERR invalid expire time in expire" {r EXPIRE foo -9999999999999999}
|
||||
|
||||
r ttl foo
|
||||
} {-1}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue