From bf643a63c8482aa00aa6792c2383f7a0499edc1f Mon Sep 17 00:00:00 2001 From: "debing.sun" Date: Tue, 6 Aug 2024 20:40:46 +0800 Subject: [PATCH] Ensure validity of myself as master or replica when loading cluster config (#13443) First, we need to ensure that `curmaster` in `clusterUpdateSlotsConfigWith()` is not NULL in the line https://github.com/redis/redis/blob/82f00f5179720c8cee6cd650763d184ba943be92/src/cluster_legacy.c#L2320 otherwise, it will crash in the https://github.com/redis/redis/blob/82f00f5179720c8cee6cd650763d184ba943be92/src/cluster_legacy.c#L2395 So when loading cluster node config, we need to ensure that the following conditions are met: 1. A node must be at least one of the master or replica. 2. If a node is a replica, its master can't be NULL. --- src/cluster_legacy.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/cluster_legacy.c b/src/cluster_legacy.c index cdea50e25..ef5822016 100644 --- a/src/cluster_legacy.c +++ b/src/cluster_legacy.c @@ -634,6 +634,8 @@ int clusterLoadConfig(char *filename) { } /* Config sanity check */ if (server.cluster->myself == NULL) goto fmterr; + if (!(myself->flags & (CLUSTER_NODE_MASTER | CLUSTER_NODE_SLAVE))) goto fmterr; + if (nodeIsSlave(myself) && myself->slaveof == NULL) goto fmterr; zfree(line); fclose(fp);