fix crash when SSL_CTX_new fails

Zhouyang Jia <[email protected]>
Newsgroups gmane.comp.gnome.apps.balsa
Message-ID <CABb2Tx+DkiqHPwe0HBq7==MUVoZm6SJw5AO59-EmO2VzDjOF1A@mail.gmail.com>
Hi,

I'm new to Balsa, I analyzed the source code and found a potential bug that
may cause crash.

In balsa-2.5.3/libbalsa/imap/imap-tls.c:174:26, if "SSL_CTX_new" failed to
initialize the SSL context, "SSL_CTX_set_options" would cause a crash since
"global_ssl_context" is null.

I think it's unsafe to assume that the library function would be correct.
It would be better if we could handle the error properly.

Attached please find the patch against version balsa-2.5.3. Hopefully, it
can solve this potential bug.

Best,
Zhouyang

_______________________________________________
balsa-list mailing list
[email protected]
https://mail.gnome.org/mailman/listinfo/balsa-list
balsa-2.5.3.patch (application/octet-stream, 652 B)
diff --git a/libbalsa/imap/imap-tls.c b/libbalsa/imap/imap-tls.c
index 421aa81..2ef9200 100644
--- a/libbalsa/imap/imap-tls.c
+++ b/libbalsa/imap/imap-tls.c
@@ -172,6 +172,11 @@ imap_create_ssl(void)
     /* Note: SSLv23_client_method() actually enables *all* protocols, including
      * SSLv(2|3) and TLSv1.(0|1|2), so we must switch all unsafe ones off */
     global_ssl_context = SSL_CTX_new (SSLv23_client_method ());
+    if(!global_ssl_context) {
+        fprintf(stderr, "Could not initialize SSL Context.\n");
+        return NULL;
+    }
+
 #ifdef ENABLE_SSL3
     SSL_CTX_set_options(global_ssl_context, SSL_OP_ALL|SSL_OP_NO_SSLv2);
 #else
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.