mirror of
https://gitlab.bixilon.de/bixilon/minosoft.git
synced 2025-09-15 10:25:06 -04:00
check packet length against max packet length
This commit is contained in:
parent
32fb5092c3
commit
f7dd739aad
@ -45,7 +45,6 @@ public class Network {
|
|||||||
int compressionThreshold = -1;
|
int compressionThreshold = -1;
|
||||||
Socket socket;
|
Socket socket;
|
||||||
OutputStream outputStream;
|
OutputStream outputStream;
|
||||||
InputStream cipherInputStream;
|
|
||||||
InputStream inputStream;
|
InputStream inputStream;
|
||||||
boolean encryptionEnabled = false;
|
boolean encryptionEnabled = false;
|
||||||
SecretKey secretKey;
|
SecretKey secretKey;
|
||||||
@ -78,7 +77,6 @@ public class Network {
|
|||||||
socket.setKeepAlive(true);
|
socket.setKeepAlive(true);
|
||||||
outputStream = socket.getOutputStream();
|
outputStream = socket.getOutputStream();
|
||||||
inputStream = socket.getInputStream();
|
inputStream = socket.getInputStream();
|
||||||
cipherInputStream = inputStream;
|
|
||||||
|
|
||||||
socketRThread.setName(String.format("%d/SocketR", connection.getConnectionId()));
|
socketRThread.setName(String.format("%d/SocketR", connection.getConnectionId()));
|
||||||
|
|
||||||
@ -153,7 +151,7 @@ public class Network {
|
|||||||
int length = 0;
|
int length = 0;
|
||||||
int read;
|
int read;
|
||||||
do {
|
do {
|
||||||
read = cipherInputStream.read();
|
read = inputStream.read();
|
||||||
if (read == -1) {
|
if (read == -1) {
|
||||||
disconnect();
|
disconnect();
|
||||||
return;
|
return;
|
||||||
@ -166,8 +164,12 @@ public class Network {
|
|||||||
throw new RuntimeException("VarInt is too big");
|
throw new RuntimeException("VarInt is too big");
|
||||||
}
|
}
|
||||||
} while ((read & 0b10000000) != 0);
|
} while ((read & 0b10000000) != 0);
|
||||||
|
if (length > ProtocolDefinition.PROTOCOL_PACKET_MAX_SIZE) {
|
||||||
byte[] data = cipherInputStream.readNBytes(length);
|
Log.protocol(String.format("Server sent us a to big packet (%d bytes > %d bytes)", length, ProtocolDefinition.PROTOCOL_PACKET_MAX_SIZE));
|
||||||
|
inputStream.skip(length);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
byte[] data = inputStream.readNBytes(length);
|
||||||
|
|
||||||
if (compressionThreshold >= 0) {
|
if (compressionThreshold >= 0) {
|
||||||
// compression is enabled
|
// compression is enabled
|
||||||
@ -257,7 +259,7 @@ public class Network {
|
|||||||
public void enableEncryption(SecretKey secretKey) {
|
public void enableEncryption(SecretKey secretKey) {
|
||||||
Cipher cipherEncrypt = CryptManager.createNetCipherInstance(Cipher.ENCRYPT_MODE, secretKey);
|
Cipher cipherEncrypt = CryptManager.createNetCipherInstance(Cipher.ENCRYPT_MODE, secretKey);
|
||||||
Cipher cipherDecrypt = CryptManager.createNetCipherInstance(Cipher.DECRYPT_MODE, secretKey);
|
Cipher cipherDecrypt = CryptManager.createNetCipherInstance(Cipher.DECRYPT_MODE, secretKey);
|
||||||
cipherInputStream = new CipherInputStream(inputStream, cipherDecrypt);
|
inputStream = new CipherInputStream(inputStream, cipherDecrypt);
|
||||||
outputStream = new CipherOutputStream(outputStream, cipherEncrypt);
|
outputStream = new CipherOutputStream(outputStream, cipherEncrypt);
|
||||||
encryptionEnabled = true;
|
encryptionEnabled = true;
|
||||||
Log.debug("Encryption enabled!");
|
Log.debug("Encryption enabled!");
|
||||||
|
Loading…
x
Reference in New Issue
Block a user