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:27:52 UTC

[httpcomponents-core] branch fix-backport updated: Bug fix: ensure consistency of internal buffers in case of I/O or SSL exception (back-ported from master)

This is an automated email from the ASF dual-hosted git repository.

olegk pushed a commit to branch fix-backport
in repository https://gitbox.apache.org/repos/asf/httpcomponents-core.git


The following commit(s) were added to refs/heads/fix-backport by this push:
     new f03a463  Bug fix: ensure consistency of internal buffers in case of I/O or SSL exception (back-ported from master)
f03a463 is described below

commit f03a463123599c29a285b0770b0bb4018af6eaea
Author: Oleg Kalnichevski <ol...@apache.org>
AuthorDate: Thu Jul 25 22:18:51 2019 +0200

    Bug fix: ensure consistency of internal buffers in case of I/O or SSL exception (back-ported from master)
---
 .../apache/http/nio/reactor/ssl/SSLIOSession.java  | 24 +++++++++++++++-------
 1 file changed, 17 insertions(+), 7 deletions(-)

diff --git a/httpcore-nio/src/main/java/org/apache/http/nio/reactor/ssl/SSLIOSession.java b/httpcore-nio/src/main/java/org/apache/http/nio/reactor/ssl/SSLIOSession.java
index 3abca05..5b571d8 100644
--- a/httpcore-nio/src/main/java/org/apache/http/nio/reactor/ssl/SSLIOSession.java
+++ b/httpcore-nio/src/main/java/org/apache/http/nio/reactor/ssl/SSLIOSession.java
@@ -317,9 +317,11 @@ public class SSLIOSession implements IOSession, SessionBufferStatus, SocketAcces
 
                 // 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) {
@@ -430,10 +432,14 @@ public class SSLIOSession implements IOSession, SessionBufferStatus, SocketAcces
         // Acquire buffer
         final ByteBuffer outEncryptedBuf = this.outEncrypted.acquire();
 
+        final int bytesWritten;
         // Perform operation
         outEncryptedBuf.flip();
-        final int bytesWritten = this.session.channel().write(outEncryptedBuf);
-        outEncryptedBuf.compact();
+        try {
+            bytesWritten = this.session.channel().write(outEncryptedBuf);
+        } finally {
+            outEncryptedBuf.compact();
+        }
 
         // Release if empty
         if (outEncryptedBuf.position() == 0) {
@@ -470,10 +476,14 @@ public class SSLIOSession implements IOSession, SessionBufferStatus, SocketAcces
             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) {