feat(fuzz): add rcon & query fuzzing

This commit is contained in:
Alexander Medvedev
2026-05-01 19:35:15 +02:00
parent 8060283970
commit 44270fbde1
7 changed files with 3003 additions and 49 deletions

View File

@@ -26,7 +26,7 @@ impl Default for RCONConfig {
enabled: false,
address: SocketAddr::new(Ipv4Addr::UNSPECIFIED.into(), 25575),
password: String::new(),
max_connections: 0,
max_connections: 10,
logging: RCONLogging::default(),
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -19,6 +19,9 @@ libfuzzer-sys = "0.4"
[dependencies.pumpkin-protocol]
path = ".."
[dependencies.pumpkin]
path = "../../pumpkin"
[dependencies.pumpkin-util]
path = "../../pumpkin-util"
@@ -49,3 +52,17 @@ path = "fuzz_targets/encoder_bedrock.rs"
test = false
doc = false
bench = false
[[bin]]
name = "query_decoder"
path = "fuzz_targets/query_decoder.rs"
test = false
doc = false
bench = false
[[bin]]
name = "rcon_decoder"
path = "fuzz_targets/rcon_decoder.rs"
test = false
doc = false
bench = false

View File

@@ -0,0 +1,21 @@
#![no_main]
use libfuzzer_sys::fuzz_target;
use pumpkin_protocol::query::{RawQueryPacket, SHandshake, SStatusRequest};
use tokio::runtime::Runtime;
fuzz_target!(|data: &[u8]| {
let rt = Runtime::new().unwrap();
rt.block_on(async {
if let Ok(mut raw) = RawQueryPacket::decode(data.to_vec()).await {
match raw.packet_type {
pumpkin_protocol::query::PacketType::Handshake => {
let _ = SHandshake::decode(&mut raw).await;
}
pumpkin_protocol::query::PacketType::Status => {
let _ = SStatusRequest::decode(&mut raw).await;
}
}
}
});
});

View File

@@ -0,0 +1,8 @@
#![no_main]
use libfuzzer_sys::fuzz_target;
use pumpkin::net::rcon::packet::Packet;
fuzz_target!(|data: &[u8]| {
let mut incoming = data.to_vec();
let _ = Packet::deserialize(&mut incoming);
});

View File

@@ -12,7 +12,7 @@ use tracing::{debug, error, info};
use crate::command::CommandSender;
use crate::{SHOULD_STOP, STOP_INTERRUPT, server::Server};
mod packet;
pub mod packet;
pub struct RCONServer;

View File

@@ -14,6 +14,7 @@ pub enum ServerboundPacket {
}
impl ServerboundPacket {
#[must_use]
pub const fn from_i32(n: i32) -> Self {
match n {
// 3 => Self::Auth,
@@ -34,6 +35,7 @@ pub enum ClientboundPacket {
}
impl ClientboundPacket {
#[must_use]
pub fn write_buf(self, id: i32, body: &str) -> BytesMut {
// let len = outgoing.len() as u64;
let mut buf = BytesMut::new();
@@ -119,14 +121,17 @@ impl Packet {
}))
}
#[must_use]
pub fn get_body(&self) -> &str {
&self.body
}
#[must_use]
pub const fn get_type(&self) -> ServerboundPacket {
self.ptype
}
#[must_use]
pub const fn get_id(&self) -> i32 {
self.id
}