Unverified Commit 9273d09d authored by Binbin's avatar Binbin Committed by GitHub
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.
parent a3a01429
...@@ -268,9 +268,17 @@ start_server {tags {"expire"}} { ...@@ -268,9 +268,17 @@ start_server {tags {"expire"}} {
test {EXPIRE with big integer overflows when converted to milliseconds} { test {EXPIRE with big integer overflows when converted to milliseconds} {
r set foo bar r set foo bar
catch {r EXPIRE foo 10000000000000000} e
set e # Hit `when > LLONG_MAX - basetime`
} {ERR invalid expire time in expire} 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} { test {PEXPIRE with big integer overflow when basetime is added} {
r set foo bar r set foo bar
...@@ -280,8 +288,11 @@ start_server {tags {"expire"}} { ...@@ -280,8 +288,11 @@ start_server {tags {"expire"}} {
test {EXPIRE with big negative integer} { test {EXPIRE with big negative integer} {
r set foo bar 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 r ttl foo
} {-1} } {-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