From 009bf5476ace1254eb98ea199affeb065f928b2d Mon Sep 17 00:00:00 2001 From: Jun He Date: Mon, 3 Jul 2017 07:18:32 +0000 Subject: [PATCH 01/10] Fixed stack trace generation on aarch64 Change-Id: I9801239c98cb7362ed07e8b9ec2ba7e45749dba7 Signed-off-by: Jun He --- src/Makefile | 2 +- src/debug.c | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/Makefile b/src/Makefile index 24e960593..a1ff4258a 100644 --- a/src/Makefile +++ b/src/Makefile @@ -39,7 +39,7 @@ endif endif # To get ARM stack traces if Redis crashes we need a special C flag. -ifneq (,$(findstring armv,$(uname_M))) +ifneq (,$(filter aarch64 armv,$(uname_M))) CFLAGS+=-funwind-tables endif diff --git a/src/debug.c b/src/debug.c index a4caa49f2..c976d0ed9 100644 --- a/src/debug.c +++ b/src/debug.c @@ -673,6 +673,8 @@ static void *getMcontextEip(ucontext_t *uc) { return (void*) uc->uc_mcontext.sc_ip; #elif defined(__arm__) /* Linux ARM */ return (void*) uc->uc_mcontext.arm_pc; + #elif defined(__aarch64__) /* Linux AArch64 */ + return (void*) uc->uc_mcontext.pc; #endif #else return NULL; From 32c2185ff54ad1df295e9bf99bc77ac4d32190a2 Mon Sep 17 00:00:00 2001 From: "dejun.xdj" Date: Tue, 10 Apr 2018 16:36:05 +0800 Subject: [PATCH 02/10] Bugfix: xadd comand arity check missing parenthesis causes wrong arithmetic priority. --- src/t_stream.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/t_stream.c b/src/t_stream.c index 4640f0b2c..076ccf21d 100644 --- a/src/t_stream.c +++ b/src/t_stream.c @@ -1009,7 +1009,7 @@ void xaddCommand(client *c) { int field_pos = i+1; /* Check arity. */ - if ((c->argc - field_pos) < 2 || (c->argc-field_pos % 2) == 1) { + if ((c->argc - field_pos) < 2 || ((c->argc-field_pos) % 2) == 1) { addReplyError(c,"wrong number of arguments for XADD"); return; } From 50eeff67b0614ee78fd67ab6a67ffaf994d76cfd Mon Sep 17 00:00:00 2001 From: "dejun.xdj" Date: Wed, 16 May 2018 16:15:12 +0800 Subject: [PATCH 03/10] Add warning message when using password on command line --- src/redis-cli.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/redis-cli.c b/src/redis-cli.c index d80973e75..712c5b92a 100644 --- a/src/redis-cli.c +++ b/src/redis-cli.c @@ -1088,6 +1088,7 @@ static int parseOptions(int argc, char **argv) { } else if (!strcmp(argv[i],"-n") && !lastarg) { config.dbnum = atoi(argv[++i]); } else if (!strcmp(argv[i],"-a") && !lastarg) { + fputs("Warning: Using a password on the command line interface can be insecure.\n", stderr); config.auth = argv[++i]; } else if (!strcmp(argv[i],"-u") && !lastarg) { parseRedisUri(argv[++i]); From 0e070f8e1e2403be72a4bc1d9e1d4d60431c297f Mon Sep 17 00:00:00 2001 From: "dejun.xdj" Date: Wed, 16 May 2018 16:18:00 +0800 Subject: [PATCH 04/10] Stop saving auth command in redis-cli history. --- src/redis-cli.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/redis-cli.c b/src/redis-cli.c index 712c5b92a..866125ec6 100644 --- a/src/redis-cli.c +++ b/src/redis-cli.c @@ -1399,8 +1399,10 @@ static void repl(void) { while((line = linenoise(context ? config.prompt : "not connected> ")) != NULL) { if (line[0] != '\0') { argv = cliSplitArgs(line,&argc); - if (history) linenoiseHistoryAdd(line); - if (historyfile) linenoiseHistorySave(historyfile); + if (strcasecmp(argv[0], "auth")) { + if (history) linenoiseHistoryAdd(line); + if (historyfile) linenoiseHistorySave(historyfile); + } if (argv == NULL) { printf("Invalid argument(s)\n"); From 9eb550dc82843b6965ff2d4e79c2a8a693eead25 Mon Sep 17 00:00:00 2001 From: "dejun.xdj" Date: Fri, 18 May 2018 11:37:31 +0800 Subject: [PATCH 05/10] Change the warning message a little bit to avoid trademark issuses. --- src/redis-cli.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/redis-cli.c b/src/redis-cli.c index 866125ec6..13cfe8a02 100644 --- a/src/redis-cli.c +++ b/src/redis-cli.c @@ -1088,7 +1088,7 @@ static int parseOptions(int argc, char **argv) { } else if (!strcmp(argv[i],"-n") && !lastarg) { config.dbnum = atoi(argv[++i]); } else if (!strcmp(argv[i],"-a") && !lastarg) { - fputs("Warning: Using a password on the command line interface can be insecure.\n", stderr); + fputs("Warning: Using a password with '-a' option on the command line interface may not be safe.\n", stderr); config.auth = argv[++i]; } else if (!strcmp(argv[i],"-u") && !lastarg) { parseRedisUri(argv[++i]); From 8ce9da0e9cfa6db74c7ef2c4b851a08c51db7feb Mon Sep 17 00:00:00 2001 From: "dejun.xdj" Date: Fri, 18 May 2018 11:40:05 +0800 Subject: [PATCH 06/10] Detect and stop saving history for auth command with repeat option. Put the repeat option checking code a little forward to avoid repeat logic. --- src/redis-cli.c | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/src/redis-cli.c b/src/redis-cli.c index 13cfe8a02..17b02641f 100644 --- a/src/redis-cli.c +++ b/src/redis-cli.c @@ -1398,8 +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; + argv = cliSplitArgs(line,&argc); - if (strcasecmp(argv[0], "auth")) { + + /* check if we have a repeat command option and + * need to skip the first arg */ + if (argv && argc > 0) { + repeat = strtol(argv[0], &endptr, 10); + if (argc > 1 && *endptr == '\0' && repeat) { + skipargs = 1; + } else { + repeat = 1; + } + } + + /* Won't save auth command in history file */ + if (!(argv && argc > 0 && !strcasecmp(argv[0+skipargs], "auth"))) { if (history) linenoiseHistoryAdd(line); if (historyfile) linenoiseHistorySave(historyfile); } @@ -1434,15 +1450,6 @@ static void repl(void) { linenoiseClearScreen(); } else { long long start_time = mstime(), elapsed; - int repeat, skipargs = 0; - char *endptr; - - repeat = strtol(argv[0], &endptr, 10); - if (argc > 1 && *endptr == '\0' && repeat) { - skipargs = 1; - } else { - repeat = 1; - } issueCommandRepeat(argc-skipargs, argv+skipargs, repeat); From dc4be43b57a8458d88ae5db906f9aecbb92fe261 Mon Sep 17 00:00:00 2001 From: "dejun.xdj" Date: Sat, 19 May 2018 22:50:40 +0800 Subject: [PATCH 07/10] 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 17b02641f..54b0d8f88 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; From fab8975463546a9e27016802e561ded2a8b62ec7 Mon Sep 17 00:00:00 2001 From: "dejun.xdj" Date: Mon, 21 May 2018 12:04:53 +0800 Subject: [PATCH 08/10] Change the type of repeat argument to long for function cliSendCommand. To be in consistent with the original definition. --- src/redis-cli.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/redis-cli.c b/src/redis-cli.c index 54b0d8f88..9bbea0fe2 100644 --- a/src/redis-cli.c +++ b/src/redis-cli.c @@ -917,7 +917,7 @@ static int cliReadReply(int output_raw_strings) { return REDIS_OK; } -static int cliSendCommand(int argc, char **argv, int repeat) { +static int cliSendCommand(int argc, char **argv, long repeat) { char *command = argv[0]; size_t *argvlen; int j, output_raw; From 5e0261c0ebcd94848de436f52844cd3e3ba9a6f6 Mon Sep 17 00:00:00 2001 From: "dejun.xdj" Date: Mon, 21 May 2018 12:06:48 +0800 Subject: [PATCH 09/10] Check if the repeat value is positive in while loop of cliSendCommand(). In case that the incoming repeat parameter is negative and causes a deadless loop. --- src/redis-cli.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/redis-cli.c b/src/redis-cli.c index 9bbea0fe2..feddf378c 100644 --- a/src/redis-cli.c +++ b/src/redis-cli.c @@ -980,7 +980,7 @@ static int cliSendCommand(int argc, char **argv, long repeat) { for (j = 0; j < argc; j++) argvlen[j] = sdslen(argv[j]); - while(repeat--) { + while(repeat-- > 0) { redisAppendCommandArgv(context,argc,(const char**)argv,argvlen); while (config.monitor_mode) { if (cliReadReply(output_raw) != REDIS_OK) exit(1); From aac27d834da13bd20977aa053b952527bdba2766 Mon Sep 17 00:00:00 2001 From: "dejun.xdj" Date: Mon, 21 May 2018 12:19:37 +0800 Subject: [PATCH 10/10] Fix redis-cli memory leak when sending set preference command. --- src/redis-cli.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/redis-cli.c b/src/redis-cli.c index d80973e75..1003e3768 100644 --- a/src/redis-cli.c +++ b/src/redis-cli.c @@ -1412,6 +1412,8 @@ static void repl(void) { exit(0); } else if (argv[0][0] == ':') { cliSetPreferences(argv,argc,1); + sdsfreesplitres(argv,argc); + linenoiseFree(line); continue; } else if (strcasecmp(argv[0],"restart") == 0) { if (config.eval) {