From d8e92ecc5e1cfced8bc5ed429dfb2eab5d8ae8ae Mon Sep 17 00:00:00 2001 From: attilamolnar Date: Sun, 17 Feb 2013 21:59:23 +0100 Subject: m_ssl_gnutls Fix null pointer dereference in case gnutls_xxx_get_name() returns NULL --- src/modules/extra/m_ssl_gnutls.cpp | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/modules/extra/m_ssl_gnutls.cpp b/src/modules/extra/m_ssl_gnutls.cpp index b2b65eb69..38b3700b5 100644 --- a/src/modules/extra/m_ssl_gnutls.cpp +++ b/src/modules/extra/m_ssl_gnutls.cpp @@ -195,6 +195,12 @@ class ModuleSSLGnuTLS : public Module GenericCap capHandler; ServiceProvider iohook; + + inline static const char* UnknownIfNULL(const char* str) + { + return str ? str : "UNKNOWN"; + } + public: ModuleSSLGnuTLS() @@ -701,10 +707,12 @@ class ModuleSSLGnuTLS : public Module { if (sessions[user->eh.GetFd()].sess) { + const gnutls_session_t& sess = sessions[user->eh.GetFd()].sess; + std::string cipher = UnknownIfNULL(gnutls_kx_get_name(gnutls_kx_get(sess))); + cipher.append("-").append(UnknownIfNULL(gnutls_cipher_get_name(gnutls_cipher_get(sess)))).append("-"); + cipher.append(UnknownIfNULL(gnutls_mac_get_name(gnutls_mac_get(sess)))); + ssl_cert* cert = sessions[user->eh.GetFd()].cert; - std::string cipher = gnutls_kx_get_name(gnutls_kx_get(sessions[user->eh.GetFd()].sess)); - cipher.append("-").append(gnutls_cipher_get_name(gnutls_cipher_get(sessions[user->eh.GetFd()].sess))).append("-"); - cipher.append(gnutls_mac_get_name(gnutls_mac_get(sessions[user->eh.GetFd()].sess))); if (cert->fingerprint.empty()) user->WriteServ("NOTICE %s :*** You are connected using SSL cipher \"%s\"", user->nick.c_str(), cipher.c_str()); else -- cgit v1.2.3