8275811: Incorrect instance to dispose

Reviewed-by: xuelei
This commit is contained in:
Daniel Jelinski 2021-11-16 20:34:15 +00:00 committed by Xue-Lei Andrew Fan
parent b0a463fa59
commit cddc6ce446
4 changed files with 35 additions and 3 deletions

View file

@ -122,7 +122,7 @@ abstract class InputRecord implements Record, Closeable {
* Since MAC's doFinal() is called for every SSL/TLS packet, it's
* not necessary to do the same with MAC's.
*/
readCipher.dispose();
this.readCipher.dispose();
this.readCipher = readCipher;
}

View file

@ -141,6 +141,11 @@ abstract class OutputRecord
// SSLEngine and SSLSocket
abstract void encodeChangeCipherSpec() throws IOException;
// SSLEngine and SSLSocket
void disposeWriteCipher() {
throw new UnsupportedOperationException();
}
// apply to SSLEngine only
Ciphertext encode(
ByteBuffer[] srcs, int srcsOffset, int srcsLength,
@ -190,7 +195,7 @@ abstract class OutputRecord
* Since MAC's doFinal() is called for every SSL/TLS packet, it's
* not necessary to do the same with MAC's.
*/
writeCipher.dispose();
disposeWriteCipher();
this.writeCipher = writeCipher;
this.isFirstAppOutputRecord = true;
@ -219,7 +224,7 @@ abstract class OutputRecord
flush();
// Dispose of any intermediate state in the underlying cipher.
writeCipher.dispose();
disposeWriteCipher();
this.writeCipher = writeCipher;
this.isFirstAppOutputRecord = true;

View file

@ -151,6 +151,15 @@ final class SSLEngineOutputRecord extends OutputRecord implements SSLRecord {
fragmenter.queueUpChangeCipherSpec();
}
@Override
void disposeWriteCipher() {
if (fragmenter == null) {
writeCipher.dispose();
} else {
fragmenter.queueUpCipherDispose();
}
}
@Override
void encodeV2NoCipher() throws IOException {
isTalkingToV2 = true;
@ -361,6 +370,7 @@ final class SSLEngineOutputRecord extends OutputRecord implements SSLRecord {
byte majorVersion;
byte minorVersion;
SSLWriteCipher encodeCipher;
boolean disposeCipher;
byte[] fragment;
}
@ -422,6 +432,15 @@ final class SSLEngineOutputRecord extends OutputRecord implements SSLRecord {
handshakeMemos.add(memo);
}
void queueUpCipherDispose() {
RecordMemo lastMemo = handshakeMemos.peekLast();
if (lastMemo != null) {
lastMemo.disposeCipher = true;
} else {
writeCipher.dispose();
}
}
Ciphertext acquireCiphertext(ByteBuffer dstBuf) throws IOException {
if (isEmpty()) {
return null;
@ -521,6 +540,9 @@ final class SSLEngineOutputRecord extends OutputRecord implements SSLRecord {
dstPos, dstLim, headerSize,
ProtocolVersion.valueOf(memo.majorVersion,
memo.minorVersion));
if (memo.disposeCipher) {
memo.encodeCipher.dispose();
}
if (SSLLogger.isOn && SSLLogger.isOn("packet")) {
ByteBuffer temporary = dstBuf.duplicate();

View file

@ -243,6 +243,11 @@ final class SSLSocketOutputRecord extends OutputRecord implements SSLRecord {
}
}
@Override
void disposeWriteCipher() {
writeCipher.dispose();
}
@Override
public void flush() throws IOException {
recordLock.lock();