aboutsummaryrefslogtreecommitdiff
path: root/openssl/src/ssl/tests/mod.rs
diff options
context:
space:
mode:
authorAlex Crichton <[email protected]>2016-12-20 14:04:10 -0800
committerAlex Crichton <[email protected]>2016-12-20 15:52:18 -0800
commit8e01f8d2502098497e642ee477d926a99ee619a8 (patch)
tree6db689d730ca6573ace1f7b876bfcf3d34cda33b /openssl/src/ssl/tests/mod.rs
parentMerge branch 'master' of github.com:sfackler/rust-openssl (diff)
downloadrust-openssl-8e01f8d2502098497e642ee477d926a99ee619a8.tar.xz
rust-openssl-8e01f8d2502098497e642ee477d926a99ee619a8.zip
Handle zero-length reads/writes
This commit adds some short-circuits for zero-length reads/writes to `SslStream`. Because OpenSSL returns 0 on error, then we could mistakenly confuse a 0-length success as an actual error, so we avoid writing or reading 0 bytes by returning quickly with a success.
Diffstat (limited to 'openssl/src/ssl/tests/mod.rs')
-rw-r--r--openssl/src/ssl/tests/mod.rs10
1 files changed, 10 insertions, 0 deletions
diff --git a/openssl/src/ssl/tests/mod.rs b/openssl/src/ssl/tests/mod.rs
index 2f6bbe1f..66f9dca9 100644
--- a/openssl/src/ssl/tests/mod.rs
+++ b/openssl/src/ssl/tests/mod.rs
@@ -421,6 +421,16 @@ fn test_write() {
stream.flush().unwrap();
}
+#[test]
+fn zero_length_buffers() {
+ let (_s, stream) = Server::new();
+ let ctx = SslContext::builder(SslMethod::tls()).unwrap();
+ let mut stream = Ssl::new(&ctx.build()).unwrap().connect(stream).unwrap();
+
+ assert_eq!(stream.write(b"").unwrap(), 0);
+ assert_eq!(stream.read(&mut []).unwrap(), 0);
+}
+
run_test!(get_peer_certificate, |method, stream| {
let ctx = SslContext::builder(method).unwrap();
let stream = Ssl::new(&ctx.build()).unwrap().connect(stream).unwrap();