Skip to content

Commit e13a5e0

Browse files
committed
Add basic fuzzing for NSString
1 parent 8d0b968 commit e13a5e0

File tree

4 files changed

+31
-8
lines changed

4 files changed

+31
-8
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -761,7 +761,7 @@ jobs:
761761
# `max_total_time`, to get more determinism.
762762
for fuzz_target in $(cargo-fuzz list --fuzz-dir=./crates/test-fuzz/)
763763
do
764-
cargo-fuzz run --fuzz-dir=./crates/test-fuzz/ $fuzz_target $ARGS -- -runs=10000 -timeout=2 -jobs=10
764+
cargo-fuzz run --fuzz-dir=./crates/test-fuzz/ $fuzz_target $ARGS,fuzz-all -- -runs=10000 -timeout=2 -jobs=10
765765
done
766766
767767
# Check if the fuzzer encountered something that should be added to

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/test-fuzz/Cargo.toml

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,21 @@ cargo-fuzz = true
1010
[dependencies]
1111
libfuzzer-sys = "0.4"
1212
objc2 = { path = "../objc2", default-features = false }
13+
icrate = { path = "../icrate", default-features = false }
1314

1415
[features]
1516
default = ["apple", "std"]
16-
std = ["objc2/std"]
17+
std = ["icrate/std"]
1718
# Runtime
18-
apple = ["objc2/apple"]
19-
gnustep-1-7 = ["objc2/gnustep-1-7"]
20-
gnustep-1-8 = ["gnustep-1-7", "objc2/gnustep-1-8"]
21-
gnustep-1-9 = ["gnustep-1-8", "objc2/gnustep-1-9"]
22-
gnustep-2-0 = ["gnustep-1-9", "objc2/gnustep-2-0"]
23-
gnustep-2-1 = ["gnustep-2-0", "objc2/gnustep-2-1"]
19+
apple = ["icrate/apple"]
20+
gnustep-1-7 = ["icrate/gnustep-1-7"]
21+
gnustep-1-8 = ["gnustep-1-7", "icrate/gnustep-1-8"]
22+
gnustep-1-9 = ["gnustep-1-8", "icrate/gnustep-1-9"]
23+
gnustep-2-0 = ["gnustep-1-9", "icrate/gnustep-2-0"]
24+
gnustep-2-1 = ["gnustep-2-0", "icrate/gnustep-2-1"]
25+
26+
# The features required for fuzzing all targets (used by CI)
27+
fuzz-all = ["icrate/Foundation", "icrate/Foundation_NSString"]
2428

2529
[[bin]]
2630
name = "class"
@@ -39,3 +43,10 @@ name = "encoding_parse"
3943
path = "fuzz_targets/encoding_parse.rs"
4044
test = false
4145
doc = false
46+
47+
[[bin]]
48+
name = "nsstring"
49+
path = "fuzz_targets/nsstring.rs"
50+
test = false
51+
doc = false
52+
required-features = ["icrate/Foundation", "icrate/Foundation_NSString"]
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#![no_main]
2+
use icrate::Foundation::NSString;
3+
use libfuzzer_sys::fuzz_target;
4+
use objc2::rc::autoreleasepool;
5+
6+
fuzz_target!(|s: &str| {
7+
autoreleasepool(|pool| {
8+
let obj = NSString::from_str(s);
9+
assert_eq!(obj.as_str(pool), s);
10+
});
11+
});

0 commit comments

Comments
 (0)