From e632e62e68cd2e4ccc65872069509d62cfa12553 Mon Sep 17 00:00:00 2001 From: Binbin Date: Wed, 2 Nov 2022 10:27:30 +0800 Subject: [PATCH] Print IP and port on cluster bus message sanity check (#11443) * Print IP and port on cluster bus message sanity check Add a print statement to indicate which IP/port is sending the error messages. That way we can at least check to see if it is a node in the cluster or some other nefarious nodes. It is proposed in #11339. Unrelated changes: the return check for connAddrPeerName should be -1 instead of C_ERR, although the value of C_ERR is also -1. Co-authored-by: Madelyn Olson <34459052+madolson@users.noreply.github.com> --- src/cluster.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/cluster.c b/src/cluster.c index 69cea4a5f..d3b800198 100644 --- a/src/cluster.c +++ b/src/cluster.c @@ -1826,7 +1826,7 @@ int nodeIp2String(char *buf, clusterLink *link, char *announced_ip) { buf[NET_IP_STR_LEN-1] = '\0'; /* We are not sure the input is sane. */ return C_OK; } else { - if (connAddrPeerName(link->conn, buf, NET_IP_STR_LEN, NULL) == C_ERR) { + if (connAddrPeerName(link->conn, buf, NET_IP_STR_LEN, NULL) == -1) { serverLog(LL_NOTICE, "Error converting peer IP to string: %s", link->conn ? connGetLastError(link->conn) : "no link"); return C_ERR; @@ -2829,9 +2829,17 @@ void clusterReadHandler(connection *conn) { if (memcmp(hdr->sig,"RCmb",4) != 0 || ntohl(hdr->totlen) < CLUSTERMSG_MIN_LEN) { - serverLog(LL_WARNING, - "Bad message length or signature received " - "from Cluster bus."); + char ip[NET_IP_STR_LEN]; + int port; + if (connAddrPeerName(conn, ip, sizeof(ip), &port) == -1) { + serverLog(LL_WARNING, + "Bad message length or signature received " + "on the Cluster bus."); + } else { + serverLog(LL_WARNING, + "Bad message length or signature received " + "on the Cluster bus from %s:%d", ip, port); + } handleLinkIOError(link); return; }