diff options
author | JJ Lu <275955589@qq.com> | 2023-05-14 14:04:33 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-05-14 09:04:33 +0300 |
commit | 11cf5cbdccee0f11f5a35e171ca78a767e18773c (patch) | |
tree | c97c73c5f1e268a8ad1717a0156702d320e1fc33 | |
parent | 29ca87955ec71ddf4525c52d86781222e1901c4f (diff) | |
download | redis-11cf5cbdccee0f11f5a35e171ca78a767e18773c.tar.gz |
Fix bug: LPOS RANK LONG_ MIN causes overflow (#12167)
Limit the range of RANK to -LONG_ MAX ~ LONG_ MAX.
Without this limit, passing -9223372036854775808 would effectively
be the same as passing -1.
-rw-r--r-- | src/t_list.c | 2 | ||||
-rw-r--r-- | tests/unit/type/list.tcl | 1 |
2 files changed, 2 insertions, 1 deletions
diff --git a/src/t_list.c b/src/t_list.c index 98c013966..6e4f629dc 100644 --- a/src/t_list.c +++ b/src/t_list.c @@ -971,7 +971,7 @@ void lposCommand(client *c) { if (!strcasecmp(opt,"RANK") && moreargs) { j++; - if (getLongFromObjectOrReply(c, c->argv[j], &rank, NULL) != C_OK) + if (getRangeLongFromObjectOrReply(c, c->argv[j], -LONG_MAX, LONG_MAX, &rank, NULL) != C_OK) return; if (rank == 0) { addReplyError(c,"RANK can't be zero: use 1 to start from " diff --git a/tests/unit/type/list.tcl b/tests/unit/type/list.tcl index 1e1ba4edc..a57e5df3e 100644 --- a/tests/unit/type/list.tcl +++ b/tests/unit/type/list.tcl @@ -464,6 +464,7 @@ foreach {type large} [array get largevalue] { assert {[r LPOS mylist c RANK -1] == 7} assert {[r LPOS mylist c RANK -2] == 6} assert_error "*RANK can't be zero: use 1 to start from the first match, 2 from the second ... or use negative to start*" {r LPOS mylist c RANK 0} + assert_error "*value is out of range*" {r LPOS mylist c RANK -9223372036854775808} } test {LPOS COUNT option} { |