mirror of
https://git.krews.org/morningstar/Arcturus-Community.git
synced 2024-11-27 00:40:52 +01:00
fix(ChannelReadHandler): patch vuln
This commit is contained in:
parent
3aa4a32a67
commit
8f5b55c9d7
@ -11,6 +11,7 @@ import io.netty.channel.ChannelHandlerContext;
|
|||||||
public class ChannelReadHandler implements Runnable {
|
public class ChannelReadHandler implements Runnable {
|
||||||
private final ChannelHandlerContext ctx;
|
private final ChannelHandlerContext ctx;
|
||||||
private final Object msg;
|
private final Object msg;
|
||||||
|
//private int _header;
|
||||||
|
|
||||||
public ChannelReadHandler(ChannelHandlerContext ctx, Object msg) {
|
public ChannelReadHandler(ChannelHandlerContext ctx, Object msg) {
|
||||||
this.ctx = ctx;
|
this.ctx = ctx;
|
||||||
@ -18,29 +19,52 @@ public class ChannelReadHandler implements Runnable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void run() {
|
public void run() {
|
||||||
ByteBuf m = (ByteBuf) this.msg;
|
try {
|
||||||
int length = m.readInt();
|
ByteBuf m = (ByteBuf) this.msg;
|
||||||
short header = m.readShort();
|
int length = m.readInt();
|
||||||
GameClient client = this.ctx.channel().attr(GameClientManager.CLIENT).get();
|
short header = m.readShort();
|
||||||
|
//_header = header;
|
||||||
|
GameClient client = this.ctx.channel().attr(GameClientManager.CLIENT).get();
|
||||||
|
|
||||||
if (client != null) {
|
if (m.readableBytes() + 2 < length) {
|
||||||
int count = 0;
|
return;
|
||||||
int timestamp = Emulator.getIntUnixTimestamp();
|
|
||||||
if (timestamp - client.lastPacketCounterCleared > 1) {
|
|
||||||
client.incomingPacketCounter.clear();
|
|
||||||
client.lastPacketCounterCleared = timestamp;
|
|
||||||
} else {
|
|
||||||
count = client.incomingPacketCounter.getOrDefault(header, 0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (count <= 10) {
|
if (client != null) {
|
||||||
count++;
|
int count = 0;
|
||||||
client.incomingPacketCounter.put((int) header, count);
|
int timestamp = Emulator.getIntUnixTimestamp();
|
||||||
ByteBuf body = Unpooled.wrappedBuffer(m.readBytes(m.readableBytes()));
|
if (timestamp - client.lastPacketCounterCleared > 1) {
|
||||||
Emulator.getGameServer().getPacketManager().handlePacket(client, new ClientMessage(header, body));
|
client.incomingPacketCounter.clear();
|
||||||
body.release();
|
client.lastPacketCounterCleared = timestamp;
|
||||||
|
} else {
|
||||||
|
if (m.readableBytes() + 2 < length) {
|
||||||
|
m.resetReaderIndex();
|
||||||
|
client.incomingPacketCounter.put((int) header, 0);
|
||||||
|
count = 0;
|
||||||
|
return;
|
||||||
|
} else {
|
||||||
|
count = client.incomingPacketCounter.getOrDefault(header, 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (count <= 10) {
|
||||||
|
count++;
|
||||||
|
if (m.readableBytes() + 2 < length) {
|
||||||
|
m.resetReaderIndex();
|
||||||
|
client.incomingPacketCounter.put((int) header, 0);
|
||||||
|
count = 0;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
client.incomingPacketCounter.put((int) header, count);
|
||||||
|
ByteBuf body = Unpooled.wrappedBuffer(m.readBytes(m.readableBytes()));
|
||||||
|
Emulator.getGameServer().getPacketManager().handlePacket(client, new ClientMessage(header, body));
|
||||||
|
body.release();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
m.release();
|
||||||
|
} catch (Exception e) {
|
||||||
|
//System.out.println("Potential packet overflow occurring, careful! header: " + _header + e.getMessage());
|
||||||
}
|
}
|
||||||
m.release();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user