mirror of
http://github.com/valkey-io/valkey
synced 2024-11-22 18:54:58 +00:00
Make sure that SELECT argument is an integer or return an error.
Unfortunately we had still the lame atoi() without any error checking in place, so "SELECT foo" would work as "SELECT 0". This was not an huge problem per se but some people expected that DB can be strings and not just numbers, and without errors you get the feeling that they can be numbers, but not the behavior. Now getLongFromObjectOrReply() is used as almost everybody else across the code, generating an error if the number is not an integer or overflows the long type. Thanks to @mipearson for reporting that on Twitter.
This commit is contained in:
parent
978e5177fd
commit
bfc197c3b6
6
src/db.c
6
src/db.c
@ -228,7 +228,11 @@ void existsCommand(redisClient *c) {
|
||||
}
|
||||
|
||||
void selectCommand(redisClient *c) {
|
||||
int id = atoi(c->argv[1]->ptr);
|
||||
long id;
|
||||
|
||||
if (getLongFromObjectOrReply(c, c->argv[1], &id,
|
||||
"invalid DB index") != REDIS_OK)
|
||||
return;
|
||||
|
||||
if (server.cluster_enabled && id != 0) {
|
||||
addReplyError(c,"SELECT is not allowed in cluster mode");
|
||||
|
Loading…
Reference in New Issue
Block a user