From 459acdeeb131dffe90721741b435a5a2ec667b58 Mon Sep 17 00:00:00 2001 From: secwall Date: Sun, 3 Sep 2023 05:14:48 +0200 Subject: [PATCH] Check shard_id pointer validity in updateShardId (#12538) When connecting between a 7.0 and 7.2 cluster, the 7.0 cluster will not populate the shard_id field, which is expect on the 7.2 cluster. This is not intended behavior, as the 7.2 cluster is supposed to use a temporary shard_id while the node is in the upgrading state, but it wasn't being correctly set in this case. (cherry picked from commit a2046c1eb1bcfcdeffadfffffad3b1f635965652) --- src/cluster.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cluster.c b/src/cluster.c index 69eff1020..c6d7e484e 100644 --- a/src/cluster.c +++ b/src/cluster.c @@ -938,13 +938,13 @@ static void updateAnnouncedHumanNodename(clusterNode *node, char *new) { static void updateShardId(clusterNode *node, const char *shard_id) { - if (memcmp(node->shard_id, shard_id, CLUSTER_NAMELEN) != 0) { + if (shard_id && memcmp(node->shard_id, shard_id, CLUSTER_NAMELEN) != 0) { clusterRemoveNodeFromShard(node); memcpy(node->shard_id, shard_id, CLUSTER_NAMELEN); clusterAddNodeToShard(shard_id, node); clusterDoBeforeSleep(CLUSTER_TODO_SAVE_CONFIG); } - if (myself != node && myself->slaveof == node) { + if (shard_id && myself != node && myself->slaveof == node) { if (memcmp(myself->shard_id, shard_id, CLUSTER_NAMELEN) != 0) { /* shard-id can diverge right after a rolling upgrade * from pre-7.2 releases */