Unverified Commit a66814fd authored by Qu Chen's avatar Qu Chen Committed by GitHub
Browse files

Make dbid range check for SWAPDB command consistent with SELECT, MOVE, and COPY. (#8555)

DB ID used to be parsed as a long for SWAPDB command, now
make it into an int to be consistent with other commands that parses
the DB ID argument like SELECT, MOVE, COPY. See #8085

The implication is that the error message when the provided db index
is greater than 4M changes slightly.
parent 18ff8cd1
...@@ -1315,7 +1315,7 @@ void scanDatabaseForReadyLists(redisDb *db) { ...@@ -1315,7 +1315,7 @@ void scanDatabaseForReadyLists(redisDb *db) {
* *
* Returns C_ERR if at least one of the DB ids are out of range, otherwise * Returns C_ERR if at least one of the DB ids are out of range, otherwise
* C_OK is returned. */ * C_OK is returned. */
int dbSwapDatabases(long id1, long id2) { int dbSwapDatabases(int id1, int id2) {
if (id1 < 0 || id1 >= server.dbnum || if (id1 < 0 || id1 >= server.dbnum ||
id2 < 0 || id2 >= server.dbnum) return C_ERR; id2 < 0 || id2 >= server.dbnum) return C_ERR;
if (id1 == id2) return C_OK; if (id1 == id2) return C_OK;
...@@ -1356,7 +1356,7 @@ int dbSwapDatabases(long id1, long id2) { ...@@ -1356,7 +1356,7 @@ int dbSwapDatabases(long id1, long id2) {
/* SWAPDB db1 db2 */ /* SWAPDB db1 db2 */
void swapdbCommand(client *c) { void swapdbCommand(client *c) {
long id1, id2; int id1, id2;
/* Not allowed in cluster mode: we have just DB 0 there. */ /* Not allowed in cluster mode: we have just DB 0 there. */
if (server.cluster_enabled) { if (server.cluster_enabled) {
...@@ -1365,11 +1365,11 @@ void swapdbCommand(client *c) { ...@@ -1365,11 +1365,11 @@ void swapdbCommand(client *c) {
} }
/* Get the two DBs indexes. */ /* Get the two DBs indexes. */
if (getLongFromObjectOrReply(c, c->argv[1], &id1, if (getIntFromObjectOrReply(c, c->argv[1], &id1,
"invalid first DB index") != C_OK) "invalid first DB index") != C_OK)
return; return;
if (getLongFromObjectOrReply(c, c->argv[2], &id2, if (getIntFromObjectOrReply(c, c->argv[2], &id2,
"invalid second DB index") != C_OK) "invalid second DB index") != C_OK)
return; return;
......
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