You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hc.apache.org by ol...@apache.org on 2019/07/25 20:59:40 UTC
[httpcomponents-core] 02/06: Bug fix: ensure consistency of
internal buffers in case of I/O or SSL exception
This is an automated email from the ASF dual-hosted git repository.
olegk pushed a commit to branch bug-fixes
in repository https://gitbox.apache.org/repos/asf/httpcomponents-core.git
commit 86007e1ee149fcd6345cc436026c19ff9db13155
Author: Oleg Kalnichevski <ol...@apache.org>
AuthorDate: Thu Jul 25 12:54:51 2019 +0200
Bug fix: ensure consistency of internal buffers in case of I/O or SSL exception
---
.../apache/hc/core5/reactor/ssl/SSLIOSession.java | 22 ++++++++++++++++------
1 file changed, 16 insertions(+), 6 deletions(-)
diff --git a/httpcore5/src/main/java/org/apache/hc/core5/reactor/ssl/SSLIOSession.java b/httpcore5/src/main/java/org/apache/hc/core5/reactor/ssl/SSLIOSession.java
index 3eb33c1..eec8cbf 100644
--- a/httpcore5/src/main/java/org/apache/hc/core5/reactor/ssl/SSLIOSession.java
+++ b/httpcore5/src/main/java/org/apache/hc/core5/reactor/ssl/SSLIOSession.java
@@ -309,8 +309,11 @@ public class SSLIOSession implements IOSession {
// Perform operations
inEncryptedBuf.flip();
- result = doUnwrap(inEncryptedBuf, inPlainBuf);
- inEncryptedBuf.compact();
+ try {
+ result = doUnwrap(inEncryptedBuf, inPlainBuf);
+ } finally {
+ inEncryptedBuf.compact();
+ }
try {
if (!inEncryptedBuf.hasRemaining() && result.getHandshakeStatus() == HandshakeStatus.NEED_UNWRAP) {
@@ -435,8 +438,11 @@ public class SSLIOSession implements IOSession {
int bytesWritten = 0;
if (outEncryptedBuf.position() > 0) {
outEncryptedBuf.flip();
- bytesWritten = this.session.channel().write(outEncryptedBuf);
- outEncryptedBuf.compact();
+ try {
+ bytesWritten = this.session.channel().write(outEncryptedBuf);
+ } finally {
+ outEncryptedBuf.compact();
+ }
}
// Release if empty
@@ -474,10 +480,14 @@ public class SSLIOSession implements IOSession {
final ByteBuffer inEncryptedBuf = this.inEncrypted.acquire();
final ByteBuffer inPlainBuf = this.inPlain.acquire();
+ final SSLEngineResult result;
// Perform operations
inEncryptedBuf.flip();
- final SSLEngineResult result = doUnwrap(inEncryptedBuf, inPlainBuf);
- inEncryptedBuf.compact();
+ try {
+ result = doUnwrap(inEncryptedBuf, inPlainBuf);
+ } finally {
+ inEncryptedBuf.compact();
+ }
try {
if (!inEncryptedBuf.hasRemaining() && result.getHandshakeStatus() == HandshakeStatus.NEED_UNWRAP) {