Fix double-free crash in BSecureSocket when cert. verification fails

* BSecureSocket::CertificateVerificationFailed() took a BCertificate
  instance by value as parameter.
  BCertificate deletes internal data in its destructor. Passing an
  object by value creates a copy, so the copy attempted to delete
  the internal data again during its destruction.
  This caused mail_daemon to crash here when it came across a failed
  certificate.

* Fix: pass BCertificate object as reference.
This commit is contained in:
Julian Harnath
2014-02-22 02:09:55 +00:00
parent 2eccf32862
commit c99d7ea45c
2 changed files with 5 additions and 4 deletions
+1 -1
View File
@@ -20,7 +20,7 @@ public:
BSecureSocket(const BSecureSocket& other); BSecureSocket(const BSecureSocket& other);
virtual ~BSecureSocket(); virtual ~BSecureSocket();
virtual bool CertificateVerificationFailed(BCertificate); virtual bool CertificateVerificationFailed(BCertificate&);
// BSocket implementation // BSocket implementation
+4 -3
View File
@@ -154,7 +154,8 @@ BSecureSocket::Private::VerifyCallback(int ok, X509_STORE_CTX* ctx)
return 0; return 0;
// Let the BSecureSocket (or subclass) decide if we should continue anyway. // Let the BSecureSocket (or subclass) decide if we should continue anyway.
return socket->CertificateVerificationFailed(BCertificate(certificate)); BCertificate failedCertificate(certificate);
return socket->CertificateVerificationFailed(failedCertificate);
} }
@@ -285,7 +286,7 @@ BSecureSocket::WaitForReadable(bigtime_t timeout) const
bool bool
BSecureSocket::CertificateVerificationFailed(BCertificate) BSecureSocket::CertificateVerificationFailed(BCertificate&)
{ {
// Until apps actually make use of the certificate API, let's keep the old // Until apps actually make use of the certificate API, let's keep the old
// behavior and accept all connections, even if the certificate validation // behavior and accept all connections, even if the certificate validation
@@ -357,7 +358,7 @@ BSecureSocket::~BSecureSocket()
bool bool
BSecureSocket::CertificateVerificationFailed(BCertificate) BSecureSocket::CertificateVerificationFailed(BCertificate&)
{ {
return false; return false;
} }