// libFuzzer harness for the Mach-O object file reader. // Build with: cmake -DVOIDLIBC_BUILD_FUZZ=ON ... // Run: ./fuzz_macho_reader [-max_total_time=60] [corpus_dir] #include "voidlink/macho_reader.hpp" #include #include #include #include extern "C" int LLVMFuzzerTestOneInput(const std::uint8_t* data, std::size_t size) { const int fd = static_cast(::syscall(SYS_memfd_create, "fuzz_macho", 0)); if (fd < 0) return 0; const std::uint8_t* p = data; std::size_t rem = size; while (rem > 0) { const ssize_t n = ::write(fd, p, rem); if (n <= 0) break; p += static_cast(n); rem -= static_cast(n); } char path[64]; std::snprintf(path, sizeof(path), "/proc/self/fd/%d", fd); (void)voidlibc::voidlink::macho::parse_macho_object(path); ::close(fd); return 0; }