Commit 8fca090e authored by Binbin's avatar Binbin Committed by Oran Agra
Browse files

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.

(cherry picked from commit 9273d09d)
parent e38d0b5a
......@@ -236,9 +236,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
......@@ -248,8 +256,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}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment