Reject MOVE to non-integer DBs

Previously, "MOVE key somestring" would move the key to
DB 0 which is just unexpected and wrong.
String as DB == error.

Test added too.

Modified by @antirez in order to use the getLongLongFromObject() API
instead of strtol().

Fixes #1428
This commit is contained in:
Matt Stancliff 2014-08-01 14:55:24 -04:00 committed by antirez
parent 25791550e0
commit 498ad7482b
2 changed files with 12 additions and 1 deletions

View File

@ -707,6 +707,7 @@ void moveCommand(redisClient *c) {
robj *o;
redisDb *src, *dst;
int srcid;
long long dbid;
if (server.cluster_enabled) {
addReplyError(c,"MOVE is not allowed in cluster mode");
@ -716,7 +717,11 @@ void moveCommand(redisClient *c) {
/* Obtain source and target DB pointers */
src = c->db;
srcid = c->db->id;
if (selectDb(c,atoi(c->argv[2]->ptr)) == REDIS_ERR) {
if (getLongLongFromObject(c->argv[2],&dbid) == REDIS_ERR ||
dbid < INT_MIN || dbid > INT_MAX ||
selectDb(c,dbid) == REDIS_ERR)
{
addReply(c,shared.outofrangeerr);
return;
}

View File

@ -404,6 +404,12 @@ start_server {tags {"basic"}} {
r move mykey 10
} {0}
test {MOVE against non-integer DB (#1428)} {
r set mykey hello
catch {r move mykey notanumber} e
set e
} {*ERR*index out of range}
test {SET/GET keys in different DBs} {
r set a hello
r set b world