From 18b59f35ef491ad0d550a907149d4c6a3b3c6a30 Mon Sep 17 00:00:00 2001 From: Wen Hui Date: Tue, 16 Mar 2021 06:23:19 -0400 Subject: [PATCH] Sentinel: fix potential NULL ptr issue for sentinel instance connection (#8627) --- src/sentinel.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/sentinel.c b/src/sentinel.c index 9c40e3d06..b598cd732 100644 --- a/src/sentinel.c +++ b/src/sentinel.c @@ -2423,8 +2423,10 @@ void sentinelReconnectInstance(sentinelRedisInstance *ri) { /* Commands connection. */ if (link->cc == NULL) { link->cc = redisAsyncConnectBind(ri->addr->ip,ri->addr->port,NET_FIRST_BIND_ADDR); - if (!link->cc->err) anetCloexec(link->cc->c.fd); - if (!link->cc->err && server.tls_replication && + if (link->cc && !link->cc->err) anetCloexec(link->cc->c.fd); + if (!link->cc) { + sentinelEvent(LL_DEBUG,"-cmd-link-reconnection",ri,"%@ #Failed to establish connection"); + } else if (!link->cc->err && server.tls_replication && (instanceLinkNegotiateTLS(link->cc) == C_ERR)) { sentinelEvent(LL_DEBUG,"-cmd-link-reconnection",ri,"%@ #Failed to initialize TLS"); instanceLinkCloseConnection(link,link->cc); @@ -2451,8 +2453,10 @@ void sentinelReconnectInstance(sentinelRedisInstance *ri) { /* Pub / Sub */ if ((ri->flags & (SRI_MASTER|SRI_SLAVE)) && link->pc == NULL) { link->pc = redisAsyncConnectBind(ri->addr->ip,ri->addr->port,NET_FIRST_BIND_ADDR); - if (!link->pc->err) anetCloexec(link->pc->c.fd); - if (!link->pc->err && server.tls_replication && + if (link->pc && !link->pc->err) anetCloexec(link->pc->c.fd); + if (!link->pc) { + sentinelEvent(LL_DEBUG,"-pubsub-link-reconnection",ri,"%@ #Failed to establish connection"); + } else if (!link->pc->err && server.tls_replication && (instanceLinkNegotiateTLS(link->pc) == C_ERR)) { sentinelEvent(LL_DEBUG,"-pubsub-link-reconnection",ri,"%@ #Failed to initialize TLS"); } else if (link->pc->err) {