summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordejun.xdj <dejun.xdj@alibaba-inc.com>2018-05-19 22:50:40 +0800
committerantirez <antirez@gmail.com>2018-05-29 12:46:27 +0200
commit7a565d725738e007ca6901abfa7cedab6b4e1d10 (patch)
tree350ade7bc65064a78798f3cba71077fbe3013d4c
parent64bf60fb52406b20ef3dce3b94ed204d8e9f2fb0 (diff)
downloadredis-7a565d725738e007ca6901abfa7cedab6b4e1d10.tar.gz
Fix negtive repeat command value issue.
If command like "-1 set a b" is sent with redis-cli, it will cause a deadless loop. So some repeat value checking logic is added to avoid this.
-rw-r--r--src/redis-cli.c14
1 files changed, 11 insertions, 3 deletions
diff --git a/src/redis-cli.c b/src/redis-cli.c
index f4a550094..db21a3931 100644
--- a/src/redis-cli.c
+++ b/src/redis-cli.c
@@ -1398,16 +1398,24 @@ static void repl(void) {
cliRefreshPrompt();
while((line = linenoise(context ? config.prompt : "not connected> ")) != NULL) {
if (line[0] != '\0') {
- int repeat = 1, skipargs = 0;
- char *endptr;
+ long repeat = 1;
+ int skipargs = 0;
+ char *endptr = NULL;
argv = cliSplitArgs(line,&argc);
/* check if we have a repeat command option and
* need to skip the first arg */
if (argv && argc > 0) {
+ errno = 0;
repeat = strtol(argv[0], &endptr, 10);
- if (argc > 1 && *endptr == '\0' && repeat) {
+ if (argc > 1 && *endptr == '\0') {
+ if (errno == ERANGE || errno == EINVAL || repeat <= 0) {
+ fputs("Invalid redis-cli repeat command option value.\n", stdout);
+ sdsfreesplitres(argv, argc);
+ linenoiseFree(line);
+ continue;
+ }
skipargs = 1;
} else {
repeat = 1;