diff options
author | Wen Hui <wen.hui.ware@gmail.com> | 2021-03-16 06:23:19 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-03-16 12:23:19 +0200 |
commit | 18b59f35ef491ad0d550a907149d4c6a3b3c6a30 (patch) | |
tree | dbafab8209ecbb56900b766f63c0baf4e20e72aa /src/sentinel.c | |
parent | 40d555dbb72d0294ea35dcf8af45ecdbb28d5095 (diff) | |
download | redis-18b59f35ef491ad0d550a907149d4c6a3b3c6a30.tar.gz |
Sentinel: fix potential NULL ptr issue for sentinel instance connection (#8627)
Diffstat (limited to 'src/sentinel.c')
-rw-r--r-- | src/sentinel.c | 12 |
1 files 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) { |