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 <caozb@yidingyun.com>
Co-authored-by: Oran Agra <oran@redislabs.com>
(cherry picked from commit a295770e32b4bd71ff560c5ec7bc5c0ad12bf068)
This commit is contained in:
caozb 2020-09-27 20:40:07 +08:00 committed by Oran Agra
parent 9418083770
commit 63075b81e6

View File

@ -464,8 +464,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) {