From a11ae95cdfcaeb7633a05e4566a56c1b909d274d Mon Sep 17 00:00:00 2001 From: Roshan Khatri Date: Tue, 16 Jul 2024 23:10:27 +0000 Subject: [PATCH] remove unsafe call to getNodeFromLinkAndMsg Signed-off-by: Roshan Khatri --- src/cluster_legacy.c | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/src/cluster_legacy.c b/src/cluster_legacy.c index df5d704dc8..1eaa24d4fa 100644 --- a/src/cluster_legacy.c +++ b/src/cluster_legacy.c @@ -3039,23 +3039,29 @@ int clusterProcessPacket(clusterLink *link) { } return 1; } - + clusterNode *sender; clusterMsg *hdr = (clusterMsg *)link->rcvbuf; - clusterNode *sender = getNodeFromLinkAndMsg(link, hdr); uint16_t type = ntohs(hdr->type); mstime_t now = mstime(); + if (type == CLUSTERMSG_TYPE_PUBLISH_LIGHT || type == CLUSTERMSG_TYPE_PUBLISHSHARD_LIGHT) { + if (!link->node || nodeInHandshake(link->node)) { + freeClusterLink(link); + serverLog(LL_WARNING, "Closing link for node that sent a lightweight message of type %hu as its first message on the link", type); + return 0; + } + sender = link->node; + sender->data_received = now; + return pubsubProcessLightPacket(link, type); + } + + sender = getNodeFromLinkAndMsg(link, hdr); /* Update the last time we saw any data from this node. We * use this in order to avoid detecting a timeout from a node that * is just sending a lot of data in the cluster bus, for instance * because of Pub/Sub. */ if (sender) sender->data_received = now; - if (sender && (type == CLUSTERMSG_TYPE_PUBLISH_LIGHT || type == CLUSTERMSG_TYPE_PUBLISHSHARD_LIGHT) && - nodeSupportsLightMsgHdr(sender)) { - return pubsubProcessLightPacket(link, type); - } - uint16_t flags = ntohs(hdr->flags); uint64_t sender_claimed_current_epoch = 0, sender_claimed_config_epoch = 0; int sender_claims_to_be_primary = !memcmp(hdr->replicaof, CLUSTER_NODE_NULL_NAME, CLUSTER_NAMELEN); @@ -3066,7 +3072,6 @@ int clusterProcessPacket(clusterLink *link) { sender->flags |= CLUSTER_NODE_EXTENSIONS_SUPPORTED; } - if (sender && (hdr->mflags[0] & CLUSTERMSG_FLAG0_EXT_DATA)) { sender->flags |= CLUSTER_NODE_EXTENSIONS_SUPPORTED; }