mirror of https://mirror.osredm.com/root/redis.git
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.
This commit is contained in:
parent
29ca87955e
commit
11cf5cbdcc
|
@ -971,7 +971,7 @@ void lposCommand(client *c) {
|
||||||
|
|
||||||
if (!strcasecmp(opt,"RANK") && moreargs) {
|
if (!strcasecmp(opt,"RANK") && moreargs) {
|
||||||
j++;
|
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;
|
return;
|
||||||
if (rank == 0) {
|
if (rank == 0) {
|
||||||
addReplyError(c,"RANK can't be zero: use 1 to start from "
|
addReplyError(c,"RANK can't be zero: use 1 to start from "
|
||||||
|
|
|
@ -464,6 +464,7 @@ foreach {type large} [array get largevalue] {
|
||||||
assert {[r LPOS mylist c RANK -1] == 7}
|
assert {[r LPOS mylist c RANK -1] == 7}
|
||||||
assert {[r LPOS mylist c RANK -2] == 6}
|
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 "*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} {
|
test {LPOS COUNT option} {
|
||||||
|
|
Loading…
Reference in New Issue