summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjengab <jen.gab@gmail.com>2021-06-08 08:34:23 +0200
committermichael-grunder <michael.grunder@gmail.com>2022-08-29 11:12:53 -0700
commit0ed6cdec35aa8bb781bd1859c3b4e6b7ec61de10 (patch)
treeb6ffb5cb7afc8d6e2ca09342eaa7cfab8ed2ba75
parent507a6dcaa5471ea395964e3166d402799f3db2fe (diff)
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.
-rw-r--r--examples/example-libevent-ssl.c2
-rw-r--r--examples/example-ssl.c7
2 files changed, 4 insertions, 5 deletions
diff --git a/examples/example-libevent-ssl.c b/examples/example-libevent-ssl.c
index 7d99af1..d0998ba 100644
--- a/examples/example-libevent-ssl.c
+++ b/examples/example-libevent-ssl.c
@@ -56,7 +56,7 @@ int main (int argc, char **argv) {
const char *caCert = argc > 5 ? argv[6] : NULL;
redisSSLContext *ssl;
- redisSSLContextError ssl_error;
+ redisSSLContextError ssl_error = REDIS_SSL_CTX_NONE;
redisInitOpenSSL();
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);
}