#3825, #3826: Check memory address availability before using natives

This commit is contained in:
Outfluencer 2025-05-12 20:45:27 +10:00 committed by md_5
parent ae2fc30b7b
commit a336efb8fa
No known key found for this signature in database
GPG Key ID: E8E901AC7C617C11

View File

@ -8,6 +8,8 @@ import com.google.common.collect.Sets;
import com.google.common.util.concurrent.ThreadFactoryBuilder; import com.google.common.util.concurrent.ThreadFactoryBuilder;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import io.netty.bootstrap.ServerBootstrap; import io.netty.bootstrap.ServerBootstrap;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import io.netty.channel.Channel; import io.netty.channel.Channel;
import io.netty.channel.ChannelException; import io.netty.channel.ChannelException;
import io.netty.channel.ChannelFuture; import io.netty.channel.ChannelFuture;
@ -230,14 +232,32 @@ public class BungeeCord extends ProxyServer
if ( !Boolean.getBoolean( "net.md_5.bungee.native.disable" ) ) if ( !Boolean.getBoolean( "net.md_5.bungee.native.disable" ) )
{ {
if ( EncryptionUtil.nativeFactory.load() ) ByteBuf directBuffer = null;
boolean hasMemoryAddress = false;
try
{
directBuffer = Unpooled.directBuffer();
hasMemoryAddress = directBuffer.hasMemoryAddress();
} finally
{
if ( directBuffer != null )
{
directBuffer.release();
}
}
if ( !hasMemoryAddress )
{
logger.warning( "Memory addresses are not available in direct buffers" );
}
if ( hasMemoryAddress && EncryptionUtil.nativeFactory.load() )
{ {
logger.info( "Using mbed TLS based native cipher." ); logger.info( "Using mbed TLS based native cipher." );
} else } else
{ {
logger.info( "Using standard Java JCE cipher." ); logger.info( "Using standard Java JCE cipher." );
} }
if ( CompressFactory.zlib.load() ) if ( hasMemoryAddress && CompressFactory.zlib.load() )
{ {
logger.info( "Using zlib based native compressor." ); logger.info( "Using zlib based native compressor." );
} else } else