Skip to content

Commit

Permalink
remove unsafe call to getNodeFromLinkAndMsg
Browse files Browse the repository at this point in the history
Signed-off-by: Roshan Khatri <[email protected]>
  • Loading branch information
roshkhatri committed Jul 16, 2024
1 parent 79dddd6 commit a11ae95
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions src/cluster_legacy.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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;
}
Expand Down

0 comments on commit a11ae95

Please sign in to comment.