From 7543920bc84fb7fe3d466543f74a6045aeee8092 Mon Sep 17 00:00:00 2001 From: dongyeonkim Date: Wed, 18 Nov 2026 17:37:52 +0900 Subject: [PATCH] Fix integer overflow in cluster bus message length validation --- src/cluster.cpp | 34 ++++++++++++++++++++++++++-------- 1 file changed, 26 insertions(+), 8 deletions(-) diff --git a/src/cluster.cpp b/src/cluster.cpp index 8e830df80..392f40255 100644 --- a/src/cluster.cpp +++ b/src/cluster.cpp @@ -1835,12 +1835,21 @@ int clusterProcessPacket(clusterLink *link) { explen += sizeof(clusterMsgDataFail); if (totlen != explen) return 1; } else if (type == CLUSTERMSG_TYPE_PUBLISH) { - uint32_t explen = sizeof(clusterMsg)-sizeof(union clusterMsgData); + uint64_t explen = sizeof(clusterMsg)-sizeof(union clusterMsgData); + + uint32_t ch_len = ntohl(hdr->data.publish.msg.channel_len); + uint32_t msg_len = ntohl(hdr->data.publish.msg.message_len); + + explen += sizeof(clusterMsgDataPublish) - 8; + explen += ch_len; + explen += msg_len; + + if (explen > UINT32_MAX) { + serverLog(LL_WARNING, + "Rejecting PUBLISH cluster message: length overflow"); + return 1; + } - explen += sizeof(clusterMsgDataPublish) - - 8 + - ntohl(hdr->data.publish.msg.channel_len) + - ntohl(hdr->data.publish.msg.message_len); if (totlen != explen) return 1; } else if (type == CLUSTERMSG_TYPE_FAILOVER_AUTH_REQUEST || type == CLUSTERMSG_TYPE_FAILOVER_AUTH_ACK || @@ -1855,10 +1864,19 @@ int clusterProcessPacket(clusterLink *link) { explen += sizeof(clusterMsgDataUpdate); if (totlen != explen) return 1; } else if (type == CLUSTERMSG_TYPE_MODULE) { - uint32_t explen = sizeof(clusterMsg)-sizeof(union clusterMsgData); + uint64_t explen = sizeof(clusterMsg)-sizeof(union clusterMsgData); + + uint32_t module_len = ntohl(hdr->data.module.msg.len); + + explen += sizeof(clusterMsgModule) - 3; + explen += module_len; + + if (explen > UINT32_MAX) { + serverLog(LL_WARNING, + "Rejecting MODULE cluster message: length overflow"); + return 1; + } - explen += sizeof(clusterMsgModule) - - 3 + ntohl(hdr->data.module.msg.len); if (totlen != explen) return 1; }