GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — SslHandler: Ensure buffers are never leaked when wrap(...) produce SS… · netty/netty@8eb6929

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • handler/src/main/java/io/netty/handler/ssl
    • SslHandler.java
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎handler/src/main/java/io/netty/handler/ssl/SslHandler.java‎

Copy file name to clipboardExpand all lines: handler/src/main/java/io/netty/handler/ssl/SslHandler.java
+31-19Lines changed: 31 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -851,27 +851,39 @@ private void wrap(ChannelHandlerContext ctx, boolean inUnwrap) throws SSLExcepti
851851

852852
SSLEngineResult result;
853853

854-
if (buf.readableBytes() > MAX_PLAINTEXT_LENGTH) {
855-
// If we pulled a buffer larger than the supported packet size, we can slice it up and iteratively,
856-
// encrypting multiple packets into a single larger buffer. This substantially saves on allocations
857-
// for large responses. Here we estimate how large of a buffer we need. If we overestimate a bit,
858-
// that's fine. If we underestimate, we'll simply re-enqueue the remaining buffer and get it on the
859-
// next outer loop.
860-
int readableBytes = buf.readableBytes();
861-
int numPackets = readableBytes / MAX_PLAINTEXT_LENGTH;
862-
if (readableBytes % MAX_PLAINTEXT_LENGTH != 0) {
863-
numPackets += 1;
864-
}
854+
try {
855+
if (buf.readableBytes() > MAX_PLAINTEXT_LENGTH) {
856+
// If we pulled a buffer larger than the supported packet size, we can slice it up and
857+
// iteratively, encrypting multiple packets into a single larger buffer. This substantially
858+
// saves on allocations for large responses. Here we estimate how large of a buffer we need.
859+
// If we overestimate a bit, that's fine. If we underestimate, we'll simply re-enqueue the
860+
// remaining buffer and get it on the next outer loop.
861+
int readableBytes = buf.readableBytes();
862+
int numPackets = readableBytes / MAX_PLAINTEXT_LENGTH;
863+
if (readableBytes % MAX_PLAINTEXT_LENGTH != 0) {
864+
numPackets += 1;
865+
}
865866

866-
if (out == null) {
867-
out = allocateOutNetBuf(ctx, readableBytes, buf.nioBufferCount() + numPackets);
868-
}
869-
result = wrapMultiple(alloc, engine, buf, out);
870-
} else {
871-
if (out == null) {
872-
out = allocateOutNetBuf(ctx, buf.readableBytes(), buf.nioBufferCount());
867+
if (out == null) {
868+
out = allocateOutNetBuf(ctx, readableBytes, buf.nioBufferCount() + numPackets);
869+
}
870+
result = wrapMultiple(alloc, engine, buf, out);
871+
} else {
872+
if (out == null) {
873+
out = allocateOutNetBuf(ctx, buf.readableBytes(), buf.nioBufferCount());
874+
}
875+
result = wrap(alloc, engine, buf, out);
873876
}
874-
result = wrap(alloc, engine, buf, out);
877+
} catch (SSLException e) {
878+
// Either wrapMultiple(...) or wrap(...) did throw. In this case we need to release the buffer
879+
// that we removed from pendingUnencryptedWrites before failing the promise and rethrowing it.
880+
// Failing to do so would result in a buffer leak.
881+
// See https://github.com/netty/netty/issues/14644
882+
//
883+
// We don't need to release out here as this is done in a finally block already.
884+
buf.release();
885+
promise.setFailure(e);
886+
throw e;
875887
}
876888

877889
if (buf.isReadable()) {

0 commit comments

Comments
0 (0)
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.