Unverified Commit 6f4f31f1 authored by yoav-steinberg's avatar yoav-steinberg Committed by GitHub
Browse files

decrby LLONG_MIN caused nagation overflow. (#9577)

Note that this breaks compatibility because in the past doing:
DECRBY x -9223372036854775808
would succeed (and create an invalid result) and now this returns an error.
parent 93e85347
...@@ -637,6 +637,11 @@ void decrbyCommand(client *c) { ...@@ -637,6 +637,11 @@ void decrbyCommand(client *c) {
long long incr; long long incr;
if (getLongLongFromObjectOrReply(c, c->argv[2], &incr, NULL) != C_OK) return; if (getLongLongFromObjectOrReply(c, c->argv[2], &incr, NULL) != C_OK) return;
/* Overflow check: negating LLONG_MIN will cause an overflow */
if (incr == LLONG_MIN) {
addReplyError(c, "decrement would overflow");
return;
}
incrDecrCommand(c,-incr); incrDecrCommand(c,-incr);
} }
......
...@@ -42,6 +42,12 @@ start_server {tags {"incr"}} { ...@@ -42,6 +42,12 @@ start_server {tags {"incr"}} {
format $err format $err
} {ERR*} } {ERR*}
test {DECRBY negation overflow} {
r set x 0
catch {r decrby x -9223372036854775808} err
format $err
} {ERR*}
test {INCR fails against a key holding a list} { test {INCR fails against a key holding a list} {
r rpush mylist 1 r rpush mylist 1
catch {r incr mylist} err catch {r incr mylist} err
......
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