Take readerIndex into account when write to BIO.

Motivation:

We should take the readerIndex into account whe write into the BIO. Its currently not a problem as we slice before and so the readerIndex is always 0 but we should better not depend on this as this will break easily if we ever refactor the code and not slice anymore.

Modifications:

Take readerIndex into acount.

Result:

More safe and correct use.
This commit is contained in:
Norman Maurer 2016-08-01 21:09:48 +02:00
parent c6a13e28b9
commit 5513514d08

View File

@ -663,7 +663,7 @@ public abstract class OpenSslContext extends SslContext {
try { try {
long bio = SSL.newMemBIO(); long bio = SSL.newMemBIO();
int readable = buffer.readableBytes(); int readable = buffer.readableBytes();
if (SSL.writeToBIO(bio, OpenSsl.memoryAddress(buffer), readable) != readable) { if (SSL.writeToBIO(bio, OpenSsl.memoryAddress(buffer) + buffer.readerIndex(), readable) != readable) {
SSL.freeBIO(bio); SSL.freeBIO(bio);
throw new IllegalStateException("Could not write data to memory BIO"); throw new IllegalStateException("Could not write data to memory BIO");
} }