Skip to content

Commit

Permalink
Add fuzzing
Browse files Browse the repository at this point in the history
  • Loading branch information
madsmtm committed Nov 10, 2022
1 parent b8f03db commit 9789b6b
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 0 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
members = [
"crates/*",
"crates/test-assembly/crates/*",
"fuzz",
]
resolver = "2"

Expand Down
2 changes: 2 additions & 0 deletions fuzz/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
corpus
artifacts
35 changes: 35 additions & 0 deletions fuzz/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
[package]
name = "fuzz"
version = "0.0.0"
publish = false
edition = "2021"

[package.metadata]
cargo-fuzz = true

[dependencies]
libfuzzer-sys = "0.4"
objc2 = { path = "../crates/objc2", default-features = false }

[features]
default = ["apple", "std"]
std = ["objc2/std"]
# Runtime
apple = ["objc2/apple"]
gnustep-1-7 = ["objc2/gnustep-1-7"]
gnustep-1-8 = ["gnustep-1-7", "objc2/gnustep-1-8"]
gnustep-1-9 = ["gnustep-1-8", "objc2/gnustep-1-9"]
gnustep-2-0 = ["gnustep-1-9", "objc2/gnustep-2-0"]
gnustep-2-1 = ["gnustep-2-0", "objc2/gnustep-2-1"]

[[bin]]
name = "class"
path = "fuzz_targets/class.rs"
test = false
doc = false

[[bin]]
name = "sel"
path = "fuzz_targets/sel.rs"
test = false
doc = false
14 changes: 14 additions & 0 deletions fuzz/fuzz_targets/class.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#![no_main]
use libfuzzer_sys::fuzz_target;
use objc2::runtime::Class;
use std::ffi::CString;

fuzz_target!(|s: &str| {
if CString::new(s).is_ok() {
#[allow(clippy::eq_op)]
if let Some(cls) = Class::get(s) {
assert_eq!(s, cls.name());
assert_eq!(cls, cls);
}
}
});
13 changes: 13 additions & 0 deletions fuzz/fuzz_targets/sel.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#![no_main]
use libfuzzer_sys::fuzz_target;
use objc2::runtime::Sel;
use std::ffi::CString;

fuzz_target!(|s: &str| {
#[allow(clippy::eq_op)]
if CString::new(s).is_ok() {
let sel = Sel::register(s);
assert_eq!(s, sel.name());
assert_eq!(sel, sel);
}
});

0 comments on commit 9789b6b

Please sign in to comment.