From 2c1da82cfed63ad6765171e96666ec1da436cdc3 Mon Sep 17 00:00:00 2001
From: Kevin Lussier <klussier@netskope.com>
Date: Fri, 9 Feb 2024 02:09:35 -0800
Subject: [PATCH] Fix the check for ":0@0" in CLUSTER NODES result (#199)

Fix the check for the `ip:port@cport` part when parsing a line in the CLUSTER NODES result. The current implementation assumes that the entire part is only 2 characters when the IP and port are not set (IP is empty and port is 0). However, this is incorrect because the `@cport` is also present in Redis 4+ so the current check fails. Additionally, there may be an optional `,hostname` as well which is not accounted for.
---
 hircluster.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/hircluster.c b/hircluster.c
index f02a943..32971e4 100644
--- a/hircluster.c
+++ b/hircluster.c
@@ -960,8 +960,8 @@ dict *parse_cluster_nodes(redisClusterContext *cc, char *str, int str_len,
                 goto error;
             }
 
-            // the address string is ":0", skip this node.
-            if (sdslen(part[1]) == 2 && strcmp(part[1], ":0") == 0) {
+            // if the address string starts with ":0", skip this node.
+            if (sdslen(part[1]) >= 2 && memcmp(part[1], ":0", 2) == 0) {
                 sdsfreesplitres(part, count_part);
                 count_part = 0;
                 part = NULL;