From 495c35d918ffc92b5fe5b7180ea722c282826460 Mon Sep 17 00:00:00 2001 From: Pierre <105686771+pieturin@users.noreply.github.com> Date: Tue, 25 Jun 2024 15:18:30 -0700 Subject: [PATCH] Add check in CLUSTERLINK KILL cmd to avoid freeing links to myself (#689) Add check in CLUSTERLINK KILL cmd to avoid freeing cluster bus links to myself. Also add an assert in `freeClusterLink()`. Testing: ``` 127.0.0.1:6379> debug clusterlink kill all c0404ee68574c6aa1048aaebfe90283afe51d2fc (error) ERR Cannot free cluster link(s) to myself ``` Signed-off-by: Pierre Turin --- src/cluster_legacy.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/cluster_legacy.c b/src/cluster_legacy.c index def572c24..b913cd567 100644 --- a/src/cluster_legacy.c +++ b/src/cluster_legacy.c @@ -1185,6 +1185,7 @@ clusterLink *createClusterLink(clusterNode *node) { * This function will just make sure that the original node associated * with this link will have the 'link' field set to NULL. */ void freeClusterLink(clusterLink *link) { + serverAssert(link != NULL); if (link->conn) { connClose(link->conn); link->conn = NULL; @@ -5815,6 +5816,10 @@ int handleDebugClusterCommand(client *c) { addReplyErrorFormat(c, "Unknown node %s", (char *)c->argv[4]->ptr); return 1; } + if (n == server.cluster->myself) { + addReplyErrorFormat(c, "Cannot free cluster link(s) to myself"); + return 1; + } /* Terminate the link based on the direction or all. */ if (!strcasecmp(c->argv[3]->ptr, "from")) {