Skip to content

Commit 1418733

Browse files
committed
[UNDERTOW-2413] CVE-2024-5971 At SslConduit.wrapAndFlip, make sure all 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)
1 parent 297da38 commit 1418733

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

core/src/main/java/io/undertow/protocols/ssl/SslConduit.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1006,13 +1006,18 @@ private synchronized long doWrap(ByteBuffer[] userBuffers, int off, int len) thr
10061006

10071007
private SSLEngineResult wrapAndFlip(ByteBuffer[] userBuffers, int off, int len) throws IOException {
10081008
SSLEngineResult result = null;
1009+
int totalConsumedBytes = 0;
10091010
while (result == null || (result.getHandshakeStatus() == SSLEngineResult.HandshakeStatus.NEED_WRAP
10101011
&& result.getStatus() != SSLEngineResult.Status.BUFFER_OVERFLOW && !engine.isInboundDone())) {
10111012
if (userBuffers == null) {
10121013
result = engine.wrap(EMPTY_BUFFER, wrappedData.getBuffer());
10131014
} else {
10141015
result = engine.wrap(userBuffers, off, len, wrappedData.getBuffer());
10151016
}
1017+
totalConsumedBytes += result.bytesConsumed();
1018+
}
1019+
if (totalConsumedBytes != result.bytesConsumed()) {
1020+
result = new SSLEngineResult(result.getStatus(), result.getHandshakeStatus(), totalConsumedBytes, result.bytesProduced());
10161021
}
10171022
wrappedData.getBuffer().flip();
10181023
return result;

0 commit comments

Comments
 (0)