From 7a565d725738e007ca6901abfa7cedab6b4e1d10 Mon Sep 17 00:00:00 2001 From: "dejun.xdj" Date: Sat, 19 May 2018 22:50:40 +0800 Subject: 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. --- src/redis-cli.c | 14 +++++++++++--- 1 file 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; -- cgit v1.2.1