Skip to content

Commit

Permalink
Fix #6082 Reduce SSL buffer compaction
Browse files Browse the repository at this point in the history
Only compact when buffer is underflown.  Note that BufferUtil will also do a cheap "compact" when flipping empty buffers.

Signed-off-by: Greg Wilkins <[email protected]>
  • Loading branch information
gregw committed Mar 22, 2021
1 parent 039c738 commit 09f39d7
Showing 1 changed file with 9 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -654,7 +654,6 @@ public int fill(ByteBuffer buffer) throws IOException
else
{
appIn = _decryptedInput;
BufferUtil.compact(_encryptedInput);
}

// Let's try reading some encrypted data... even if we have some already.
Expand Down Expand Up @@ -712,12 +711,21 @@ public int fill(ByteBuffer buffer) throws IOException
return filled = -1;

case BUFFER_UNDERFLOW:
// Can we compact?
if (_encryptedInput.position() != 0)
{
BufferUtil.compact(_encryptedInput);
continue;
}

// Are we out of space?
if (BufferUtil.space(_encryptedInput) == 0)
{
BufferUtil.clear(_encryptedInput);
throw new SSLHandshakeException("Encrypted buffer max length exceeded");
}

// if we just filled some
if (netFilled > 0)
continue; // try filling some more

Expand Down

0 comments on commit 09f39d7

Please sign in to comment.