diff options
author | Binbin <binloveplay1314@qq.com> | 2022-01-09 19:06:51 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-01-09 13:06:51 +0200 |
commit | a84c964d37a1899bf90c920efef85a1d7202d058 (patch) | |
tree | 47c816699b2764987bc92677adf3be90ce3422ff /src/networking.c | |
parent | 75c50a15633881bb2bf0455bdabcbbabc0e47044 (diff) | |
download | redis-a84c964d37a1899bf90c920efef85a1d7202d058.tar.gz |
Fix crash when error [sub]command name contains | (#10082)
The following error commands will crash redis-server:
```
> get|
Error: Server closed the connection
> get|set
Error: Server closed the connection
> get|other
```
The reason is in #9504, we use `lookupCommandBySds` for find the
container command. And it split the command (argv[0]) with `|`.
If we input something like `get|other`, after the split, `get`
will become a valid command name, pass the `ERR unknown command`
check, and finally crash in `addReplySubcommandSyntaxError`
In this case we do not need to split the command name with `|`
and just look in the commands dict to find if `argv[0]` is a
container command.
So this commit introduce a new function call `isContainerCommandBySds`
that it will return true if a command name is a container command.
Also with the old code, there is a incorrect error message:
```
> config|get set
(error) ERR Unknown subcommand or wrong number of arguments for 'set'. Try CONFIG|GET HELP.
```
The crash was reported in #10070.
Diffstat (limited to 'src/networking.c')
-rw-r--r-- | src/networking.c | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/src/networking.c b/src/networking.c index 50c7d99ca..48f248020 100644 --- a/src/networking.c +++ b/src/networking.c @@ -962,7 +962,7 @@ void addReplySubcommandSyntaxError(client *c) { sds cmd = sdsnew((char*) c->argv[0]->ptr); sdstoupper(cmd); addReplyErrorFormat(c, - "Unknown subcommand or wrong number of arguments for '%s'. Try %s HELP.", + "Unknown subcommand or wrong number of arguments for '%.128s'. Try %s HELP.", (char*)c->argv[1]->ptr,cmd); sdsfree(cmd); } |