feat(fuzz): add rcon & query fuzzing
This commit is contained in:
parent
8060283970
commit
44270fbde1
@ -26,7 +26,7 @@ impl Default for RCONConfig {
|
|||||||
enabled: false,
|
enabled: false,
|
||||||
address: SocketAddr::new(Ipv4Addr::UNSPECIFIED.into(), 25575),
|
address: SocketAddr::new(Ipv4Addr::UNSPECIFIED.into(), 25575),
|
||||||
password: String::new(),
|
password: String::new(),
|
||||||
max_connections: 0,
|
max_connections: 10,
|
||||||
logging: RCONLogging::default(),
|
logging: RCONLogging::default(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
2997
pumpkin-protocol/fuzz/Cargo.lock
generated
2997
pumpkin-protocol/fuzz/Cargo.lock
generated
File diff suppressed because it is too large
Load Diff
@ -19,6 +19,9 @@ libfuzzer-sys = "0.4"
|
|||||||
[dependencies.pumpkin-protocol]
|
[dependencies.pumpkin-protocol]
|
||||||
path = ".."
|
path = ".."
|
||||||
|
|
||||||
|
[dependencies.pumpkin]
|
||||||
|
path = "../../pumpkin"
|
||||||
|
|
||||||
[dependencies.pumpkin-util]
|
[dependencies.pumpkin-util]
|
||||||
path = "../../pumpkin-util"
|
path = "../../pumpkin-util"
|
||||||
|
|
||||||
@ -49,3 +52,17 @@ path = "fuzz_targets/encoder_bedrock.rs"
|
|||||||
test = false
|
test = false
|
||||||
doc = false
|
doc = false
|
||||||
bench = 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
|
||||||
|
|||||||
21
pumpkin-protocol/fuzz/fuzz_targets/query_decoder.rs
Normal file
21
pumpkin-protocol/fuzz/fuzz_targets/query_decoder.rs
Normal 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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
8
pumpkin-protocol/fuzz/fuzz_targets/rcon_decoder.rs
Normal file
8
pumpkin-protocol/fuzz/fuzz_targets/rcon_decoder.rs
Normal 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);
|
||||||
|
});
|
||||||
@ -12,7 +12,7 @@ use tracing::{debug, error, info};
|
|||||||
use crate::command::CommandSender;
|
use crate::command::CommandSender;
|
||||||
use crate::{SHOULD_STOP, STOP_INTERRUPT, server::Server};
|
use crate::{SHOULD_STOP, STOP_INTERRUPT, server::Server};
|
||||||
|
|
||||||
mod packet;
|
pub mod packet;
|
||||||
|
|
||||||
pub struct RCONServer;
|
pub struct RCONServer;
|
||||||
|
|
||||||
|
|||||||
@ -14,6 +14,7 @@ pub enum ServerboundPacket {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl ServerboundPacket {
|
impl ServerboundPacket {
|
||||||
|
#[must_use]
|
||||||
pub const fn from_i32(n: i32) -> Self {
|
pub const fn from_i32(n: i32) -> Self {
|
||||||
match n {
|
match n {
|
||||||
// 3 => Self::Auth,
|
// 3 => Self::Auth,
|
||||||
@ -34,6 +35,7 @@ pub enum ClientboundPacket {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl ClientboundPacket {
|
impl ClientboundPacket {
|
||||||
|
#[must_use]
|
||||||
pub fn write_buf(self, id: i32, body: &str) -> BytesMut {
|
pub fn write_buf(self, id: i32, body: &str) -> BytesMut {
|
||||||
// let len = outgoing.len() as u64;
|
// let len = outgoing.len() as u64;
|
||||||
let mut buf = BytesMut::new();
|
let mut buf = BytesMut::new();
|
||||||
@ -119,14 +121,17 @@ impl Packet {
|
|||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[must_use]
|
||||||
pub fn get_body(&self) -> &str {
|
pub fn get_body(&self) -> &str {
|
||||||
&self.body
|
&self.body
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[must_use]
|
||||||
pub const fn get_type(&self) -> ServerboundPacket {
|
pub const fn get_type(&self) -> ServerboundPacket {
|
||||||
self.ptype
|
self.ptype
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[must_use]
|
||||||
pub const fn get_id(&self) -> i32 {
|
pub const fn get_id(&self) -> i32 {
|
||||||
self.id
|
self.id
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user