From 153b8f632ba40fe7a0225fd4940d06e2a6e871f5 Mon Sep 17 00:00:00 2001 From: Yossi Gottlieb Date: Thu, 22 Aug 2019 16:19:05 +0300 Subject: SSL: Properly report SSL_connect() errors. --- sslio.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/sslio.c b/sslio.c index 25cb5c2..dc75e97 100644 --- a/sslio.c +++ b/sslio.c @@ -5,6 +5,9 @@ #ifdef HIREDIS_SSL #include #include +#include + +#include void __redisSetError(redisContext *c, int type, const char *str); @@ -143,6 +146,7 @@ int redisSslCreate(redisContext *c, const char *capath, const char *certpath, SSL_set_connect_state(s->ssl); c->flags |= REDIS_SSL; + ERR_clear_error(); int rv = SSL_connect(c->ssl->ssl); if (rv == 1) { return REDIS_OK; @@ -155,7 +159,15 @@ int redisSslCreate(redisContext *c, const char *capath, const char *certpath, } if (c->err == 0) { - __redisSetError(c, REDIS_ERR_IO, "SSL_connect() failed"); + char err[512]; + if (rv == SSL_ERROR_SYSCALL) + snprintf(err,sizeof(err)-1,"SSL_connect failed: %s",strerror(errno)); + else { + unsigned long e = ERR_peek_last_error(); + snprintf(err,sizeof(err)-1,"SSL_connect failed: %s", + ERR_reason_error_String(e)); + } + __redisSetError(c, REDIS_ERR_IO, err); } return REDIS_ERR; } -- cgit v1.2.3 From aacd4ccd7611da795b403ff5b4a24a1c4a0c49ef Mon Sep 17 00:00:00 2001 From: Yossi Gottlieb Date: Sun, 25 Aug 2019 11:43:27 +0300 Subject: Fix typo. --- sslio.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sslio.c b/sslio.c index dc75e97..0ce00c6 100644 --- a/sslio.c +++ b/sslio.c @@ -165,7 +165,7 @@ int redisSslCreate(redisContext *c, const char *capath, const char *certpath, else { unsigned long e = ERR_peek_last_error(); snprintf(err,sizeof(err)-1,"SSL_connect failed: %s", - ERR_reason_error_String(e)); + ERR_reason_error_string(e)); } __redisSetError(c, REDIS_ERR_IO, err); } -- cgit v1.2.3