Commit 9d7165e8 authored by antirez's avatar antirez
Browse files

overflow detection in INCR family functions

parent 59aee551
...@@ -346,14 +346,19 @@ void msetnxCommand(redisClient *c) { ...@@ -346,14 +346,19 @@ void msetnxCommand(redisClient *c) {
} }
void incrDecrCommand(redisClient *c, long long incr) { void incrDecrCommand(redisClient *c, long long incr) {
long long value; long long value, oldvalue;
robj *o; robj *o;
o = lookupKeyWrite(c->db,c->argv[1]); o = lookupKeyWrite(c->db,c->argv[1]);
if (o != NULL && checkType(c,o,REDIS_STRING)) return; if (o != NULL && checkType(c,o,REDIS_STRING)) return;
if (getLongLongFromObjectOrReply(c,o,&value,NULL) != REDIS_OK) return; if (getLongLongFromObjectOrReply(c,o,&value,NULL) != REDIS_OK) return;
oldvalue = value;
value += incr; value += incr;
if ((incr < 0 && value > oldvalue) || (incr > 0 && value < oldvalue)) {
addReplyError(c,"increment or decrement would overflow");
return;
}
o = createStringObjectFromLongLong(value); o = createStringObjectFromLongLong(value);
dbReplace(c->db,c->argv[1],o); dbReplace(c->db,c->argv[1],o);
touchWatchedKey(c->db,c->argv[1]); touchWatchedKey(c->db,c->argv[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