Skip to content

Commit a45b614

Browse files
authored
Merge pull request sfackler#697 from alexcrichton/release-buffers
Set SSL_MODE_RELEASE_BUFFERS by default
2 parents c800ab9 + 68a30c2 commit a45b614

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

openssl/src/ssl/connector.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use error::ErrorStack;
55
use ssl::{self, SslMethod, SslContextBuilder, SslContext, Ssl, SSL_VERIFY_PEER, SslStream,
66
HandshakeError};
77
use pkey::PKeyRef;
8+
use version;
89
use x509::X509Ref;
910

1011
#[cfg(ossl101)]
@@ -39,8 +40,17 @@ fn ctx(method: SslMethod) -> Result<SslContextBuilder, ErrorStack> {
3940
opts |= ssl::SSL_OP_CIPHER_SERVER_PREFERENCE;
4041
ctx.set_options(opts);
4142

42-
let mode = ssl::SSL_MODE_AUTO_RETRY | ssl::SSL_MODE_ACCEPT_MOVING_WRITE_BUFFER |
43+
let mut mode = ssl::SSL_MODE_AUTO_RETRY |
44+
ssl::SSL_MODE_ACCEPT_MOVING_WRITE_BUFFER |
4345
ssl::SSL_MODE_ENABLE_PARTIAL_WRITE;
46+
47+
// This is quite a useful optimization for saving memory, but historically
48+
// caused CVEs in OpenSSL pre-1.0.1h, according to
49+
// https://bugs.python.org/issue25672
50+
if version::number() >= 0x1000108f {
51+
mode |= ssl::SSL_MODE_RELEASE_BUFFERS;
52+
}
53+
4454
ctx.set_mode(mode);
4555

4656
Ok(ctx)

0 commit comments

Comments
 (0)