Skip to content

Commit

Permalink
[UNDERTOW-2413] CVE-2024-5971 At SslConduit.wrapAndFlip, make sure al…
Browse files Browse the repository at this point in the history
…l the consumed bytes of the multiple wrap calls are accounted for at the returning result.

Signed-off-by: Flavia Rainone <[email protected]>
(cherry picked from commit 74fdf63)
  • Loading branch information
fl4via committed Jul 16, 2024
1 parent 297da38 commit 1418733
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions core/src/main/java/io/undertow/protocols/ssl/SslConduit.java
Original file line number Diff line number Diff line change
Expand Up @@ -1006,13 +1006,18 @@ private synchronized long doWrap(ByteBuffer[] userBuffers, int off, int len) thr

private SSLEngineResult wrapAndFlip(ByteBuffer[] userBuffers, int off, int len) throws IOException {
SSLEngineResult result = null;
int totalConsumedBytes = 0;
while (result == null || (result.getHandshakeStatus() == SSLEngineResult.HandshakeStatus.NEED_WRAP
&& result.getStatus() != SSLEngineResult.Status.BUFFER_OVERFLOW && !engine.isInboundDone())) {
if (userBuffers == null) {
result = engine.wrap(EMPTY_BUFFER, wrappedData.getBuffer());
} else {
result = engine.wrap(userBuffers, off, len, wrappedData.getBuffer());
}
totalConsumedBytes += result.bytesConsumed();
}
if (totalConsumedBytes != result.bytesConsumed()) {
result = new SSLEngineResult(result.getStatus(), result.getHandshakeStatus(), totalConsumedBytes, result.bytesProduced());
}
wrappedData.getBuffer().flip();
return result;
Expand Down

0 comments on commit 1418733

Please sign in to comment.