From be9dd0137d60f37304e9a7d1bb0f279c2b9d98cd Mon Sep 17 00:00:00 2001 From: antirez Date: Tue, 19 Jan 2016 13:16:24 +0100 Subject: [PATCH] Cluster: check packets length before accessing far fields. --- src/cluster.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/cluster.c b/src/cluster.c index 9ca39b8f1..51cd3e216 100644 --- a/src/cluster.c +++ b/src/cluster.c @@ -1542,9 +1542,6 @@ int clusterProcessPacket(clusterLink *link) { clusterMsg *hdr = (clusterMsg*) link->rcvbuf; uint32_t totlen = ntohl(hdr->totlen); uint16_t type = ntohs(hdr->type); - uint16_t flags = ntohs(hdr->flags); - uint64_t senderCurrentEpoch = 0, senderConfigEpoch = 0; - clusterNode *sender; server.cluster->stats_bus_messages_received++; serverLog(LL_DEBUG,"--- Processing packet of type %d, %lu bytes", @@ -1552,9 +1549,17 @@ int clusterProcessPacket(clusterLink *link) { /* Perform sanity checks */ if (totlen < 16) return 1; /* At least signature, version, totlen, count. */ - if (ntohs(hdr->ver) != CLUSTER_PROTO_VER) - return 1; /* Can't handle versions other than the current one.*/ if (totlen > sdslen(link->rcvbuf)) return 1; + + if (ntohs(hdr->ver) != CLUSTER_PROTO_VER) { + /* Can't handle messages of different versions. */ + return 1; + } + + uint16_t flags = ntohs(hdr->flags); + uint64_t senderCurrentEpoch = 0, senderConfigEpoch = 0; + clusterNode *sender; + if (type == CLUSTERMSG_TYPE_PING || type == CLUSTERMSG_TYPE_PONG || type == CLUSTERMSG_TYPE_MEET) {