From 0ed6cdec35aa8bb781bd1859c3b4e6b7ec61de10 Mon Sep 17 00:00:00 2001 From: jengab Date: Tue, 8 Jun 2021 08:34:23 +0200 Subject: Fix some undefined behaviour - redisSSLContextError must always be initialized at defintion, otherwise when SSL connect succeeds it may not be assigned to a valid error. Thus the memory trash remains in the variable, which may sign a misleading error. --- examples/example-ssl.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'examples/example-ssl.c') diff --git a/examples/example-ssl.c b/examples/example-ssl.c index b8ca442..6d1e32e 100644 --- a/examples/example-ssl.c +++ b/examples/example-ssl.c @@ -12,7 +12,7 @@ int main(int argc, char **argv) { unsigned int j; redisSSLContext *ssl; - redisSSLContextError ssl_error; + redisSSLContextError ssl_error = REDIS_SSL_CTX_NONE; redisContext *c; redisReply *reply; if (argc < 4) { @@ -27,9 +27,8 @@ int main(int argc, char **argv) { redisInitOpenSSL(); ssl = redisCreateSSLContext(ca, NULL, cert, key, NULL, &ssl_error); - if (!ssl) { - printf("SSL Context error: %s\n", - redisSSLContextGetError(ssl_error)); + if (!ssl || ssl_error != REDIS_SSL_CTX_NONE) { + printf("SSL Context error: %s\n", redisSSLContextGetError(ssl_error)); exit(1); } -- cgit v1.2.3