Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 9302d381 authored by Pawan Wagh's avatar Pawan Wagh Committed by Gerrit Code Review
Browse files

Merge "Adding fuzz_service for rust backend"

parents 7d978c90 38429f00
Loading
Loading
Loading
Loading
+2 −0
Original line number Original line Diff line number Diff line
@@ -14,6 +14,8 @@ rust_bindgen {
        "--size_t-is-usize",
        "--size_t-is-usize",
        "--allowlist-function",
        "--allowlist-function",
        "createRandomParcel",
        "createRandomParcel",
        "--allowlist-function",
        "fuzzRustService",
    ],
    ],
    shared_libs: [
    shared_libs: [
        "libc++",
        "libc++",
+12 −1
Original line number Original line Diff line number Diff line
@@ -16,7 +16,8 @@


use binder::binder_impl::Parcel;
use binder::binder_impl::Parcel;
use binder::unstable_api::{AParcel, AsNative};
use binder::unstable_api::{AParcel, AsNative};
use binder_random_parcel_bindgen::createRandomParcel;
use binder::SpIBinder;
use binder_random_parcel_bindgen::{createRandomParcel, fuzzRustService};
use std::os::raw::c_void;
use std::os::raw::c_void;


/// This API creates a random parcel to be used by fuzzers
/// This API creates a random parcel to be used by fuzzers
@@ -31,3 +32,13 @@ pub fn create_random_parcel(fuzzer_data: &[u8]) -> Parcel {
    }
    }
    parcel
    parcel
}
}

/// This API automatically fuzzes provided service
pub fn fuzz_service(binder: &mut SpIBinder, fuzzer_data: &[u8]) {
    let ptr = binder.as_native_mut() as *mut c_void;
    unsafe {
        // Safety: `SpIBinder::as_native_mut` and `slice::as_ptr` always
        // return valid pointers.
        fuzzRustService(ptr, fuzzer_data.as_ptr(), fuzzer_data.len());
    }
}
+3 −0
Original line number Original line Diff line number Diff line
@@ -19,4 +19,7 @@
extern "C" {
extern "C" {
    // This API is used by rust to fill random parcel.
    // This API is used by rust to fill random parcel.
    void createRandomParcel(void* aParcel, const uint8_t* data, size_t len);
    void createRandomParcel(void* aParcel, const uint8_t* data, size_t len);

    // This API is used by fuzzers to automatically fuzz aidl services
    void fuzzRustService(void* binder, const uint8_t* data, size_t len);
}
}
 No newline at end of file
+9 −0
Original line number Original line Diff line number Diff line
@@ -29,3 +29,12 @@ void fuzzService(AIBinder* binder, FuzzedDataProvider&& provider) {
}
}


} // namespace android
} // namespace android

extern "C" {
// This API is used by fuzzers to automatically fuzz aidl services
void fuzzRustService(void* binder, const uint8_t* data, size_t len) {
    AIBinder* aiBinder = static_cast<AIBinder*>(binder);
    FuzzedDataProvider provider(data, len);
    android::fuzzService(aiBinder, std::move(provider));
}
} // extern "C"