Skip to content

Commit

Permalink
Fix fuzzing on GNUStep
Browse files Browse the repository at this point in the history
  • Loading branch information
madsmtm committed Nov 11, 2022
1 parent a7a0c04 commit fb9fc6d
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 2 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,7 @@ jobs:
# `max_total_time`, to get more determinism.
for target in $($HOME/extern/bin/cargo-fuzz list)
do
$HOME/extern/bin/cargo-fuzz run $target ${{ env.ARGS }} -- -runs=100000 -timeout=2
$HOME/extern/bin/cargo-fuzz run $target ${{ env.ARGS }} -- -runs=10000 -timeout=2 -jobs=10
done
# Check if the fuzzer encountered something that should be added to
Expand Down
3 changes: 3 additions & 0 deletions crates/objc2/src/foundation/string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use core::ffi::c_void;
use core::fmt;
use core::panic::RefUnwindSafe;
use core::panic::UnwindSafe;
#[cfg(feature = "apple")]
use core::ptr::NonNull;
use core::slice;
use core::str;
Expand Down Expand Up @@ -132,6 +133,7 @@ extern_methods!(
/// if performance is not an issue.
#[doc(alias = "CFStringGetCStringPtr")]
#[allow(unused)]
#[cfg(feature = "apple")]
// TODO: Finish this
fn as_str_wip(&self) -> Option<&str> {
type CFStringEncoding = u32;
Expand Down Expand Up @@ -160,6 +162,7 @@ extern_methods!(
///
/// [UTF-16]: https://en.wikipedia.org/wiki/UTF-16
#[allow(unused)]
#[cfg(feature = "apple")]
// TODO: Finish this
fn as_utf16(&self) -> Option<&[u16]> {
extern "C" {
Expand Down
2 changes: 1 addition & 1 deletion fuzz/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ cargo-fuzz = true

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

[features]
default = ["apple", "std"]
Expand Down
5 changes: 5 additions & 0 deletions fuzz/fuzz_targets/class.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ use objc2::runtime::Class;
use std::ffi::CString;

fuzz_target!(|s: &str| {
#[cfg(feature = "gnustep-1-7")]
unsafe {
objc2::__gnustep_hack::get_class_to_force_linkage()
};

if CString::new(s).is_ok() {
#[allow(clippy::eq_op)]
if let Some(cls) = Class::get(s) {
Expand Down
5 changes: 5 additions & 0 deletions fuzz/fuzz_targets/sel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ use objc2::runtime::Sel;
use std::ffi::CString;

fuzz_target!(|s: &str| {
#[cfg(feature = "gnustep-1-7")]
unsafe {
objc2::__gnustep_hack::get_class_to_force_linkage()
};

#[allow(clippy::eq_op)]
if CString::new(s).is_ok() {
let sel = Sel::register(s);
Expand Down

0 comments on commit fb9fc6d

Please sign in to comment.