summaryrefslogtreecommitdiff
path: root/src/t_string.c
diff options
context:
space:
mode:
authorantirez <antirez@gmail.com>2010-12-19 12:22:12 +0100
committerantirez <antirez@gmail.com>2010-12-19 12:22:12 +0100
commit9d7165e885b3de44577dea2917bb4f3afa2ed335 (patch)
treed099d8806de3bce18483ae0fb08c69a2007efde0 /src/t_string.c
parent59aee5513d27fdf2d24499f35611093fa0fab3fb (diff)
downloadredis-9d7165e885b3de44577dea2917bb4f3afa2ed335.tar.gz
overflow detection in INCR family functions
Diffstat (limited to 'src/t_string.c')
-rw-r--r--src/t_string.c7
1 files changed, 6 insertions, 1 deletions
diff --git a/src/t_string.c b/src/t_string.c
index eb080c882..c3e3607f3 100644
--- a/src/t_string.c
+++ b/src/t_string.c
@@ -346,14 +346,19 @@ void msetnxCommand(redisClient *c) {
}
void incrDecrCommand(redisClient *c, long long incr) {
- long long value;
+ long long value, oldvalue;
robj *o;
o = lookupKeyWrite(c->db,c->argv[1]);
if (o != NULL && checkType(c,o,REDIS_STRING)) return;
if (getLongLongFromObjectOrReply(c,o,&value,NULL) != REDIS_OK) return;
+ oldvalue = value;
value += incr;
+ if ((incr < 0 && value > oldvalue) || (incr > 0 && value < oldvalue)) {
+ addReplyError(c,"increment or decrement would overflow");
+ return;
+ }
o = createStringObjectFromLongLong(value);
dbReplace(c->db,c->argv[1],o);
touchWatchedKey(c->db,c->argv[1]);