From 01694608cb4e39a6ec7970d24b21ab33b7347e31 Mon Sep 17 00:00:00 2001 From: caozb <1162650653@qq.com> Date: Sun, 27 Sep 2020 20:40:07 +0800 Subject: [PATCH] ignore slaveof no one in redis.conf (#7842) when slaveof config is "no one", reset any pre-existing config and resume. also solve a memory leak if slaveof appears twice. and fail loading if port number is out of range or not an integer. Co-authored-by: caozhengbin Co-authored-by: Oran Agra --- src/config.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/config.c b/src/config.c index fbdef05b1..3d5a79eab 100644 --- a/src/config.c +++ b/src/config.c @@ -473,8 +473,17 @@ void loadServerConfigFromString(char *config) { } else if ((!strcasecmp(argv[0],"slaveof") || !strcasecmp(argv[0],"replicaof")) && argc == 3) { slaveof_linenum = linenum; + sdsfree(server.masterhost); + if (!strcasecmp(argv[1], "no") && !strcasecmp(argv[2], "one")) { + server.masterhost = NULL; + continue; + } server.masterhost = sdsnew(argv[1]); - server.masterport = atoi(argv[2]); + char *ptr; + server.masterport = strtol(argv[2], &ptr, 10); + if (server.masterport < 0 || server.masterport > 65535 || *ptr != '\0') { + err = "Invalid master port"; goto loaderr; + } server.repl_state = REPL_STATE_CONNECT; } else if (!strcasecmp(argv[0],"requirepass") && argc == 2) { if (strlen(argv[1]) > CONFIG_AUTHPASS_MAX_LEN) {