]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Fix SSL_get_peer_certificate memory leak
authorChristos Tsantilas <chtsanti@users.sourceforge.net>
Thu, 23 Apr 2015 11:55:57 +0000 (04:55 -0700)
committerAmos Jeffries <squid3@treenet.co.nz>
Thu, 23 Apr 2015 11:55:57 +0000 (04:55 -0700)
The SSL_get_peer_certificate openSSL function increases the lock for X509
object it returns so X509 object retrieved using this function must be
released with X509_free after use.
This patch uses the Ssl::X509_Pointer TidyPointer to release X509 object
retrieved with the SSL_get_peer_certificate function inside the
Ssl::PeerConnector::handleNegotiateError method

This is a Measurement Factory project

src/ssl/PeerConnector.cc

index 38845f79cd7d3c4b87c205724a6ffe279b2852bb..126dd95b220209f28384a16271bef3956fe00e43 100644 (file)
@@ -607,11 +607,13 @@ Ssl::PeerConnector::handleNegotiateError(const int ret)
         // unsupported server Hello message (TODO: make configurable).
 #if 1
         if (!SSL_get_ex_data(ssl, ssl_ex_index_ssl_error_detail) &&
-                SSL_get_peer_certificate(ssl) &&
                 (srvBio->bumpMode() == Ssl::bumpPeek  || srvBio->bumpMode() == Ssl::bumpStare) && srvBio->holdWrite()) {
-            debugs(81, 3, "Error ("  << ERR_error_string(ssl_lib_error, NULL) <<  ") but, hold write on SSL connection on FD " << fd);
-            checkForPeekAndSplice();
-            return;
+            Ssl::X509_Pointer serverCert(SSL_get_peer_certificate(ssl));
+            if (serverCert.get()) {
+                debugs(81, 3, "Error ("  << ERR_error_string(ssl_lib_error, NULL) <<  ") but, hold write on SSL connection on FD " << fd);
+                checkForPeekAndSplice();
+                return;
+            }
         }
 #endif