Files
faumaray bba5c8a39a initial commit
Signed-off-by: Aleksey Selihov <faumaray@gmail.com>
2026-05-22 02:40:32 +03:00

32 lines
909 B
C++

// libFuzzer harness for the COFF object file reader.
// Build with: cmake -DVOIDLIBC_BUILD_FUZZ=ON ...
// Run: ./fuzz_coff_reader [-max_total_time=60] [corpus_dir]
#include "voidlink/coff_reader.hpp"
#include <cstdint>
#include <cstdio>
#include <sys/syscall.h>
#include <unistd.h>
extern "C" int LLVMFuzzerTestOneInput(const std::uint8_t* data, std::size_t size) {
const int fd = static_cast<int>(::syscall(SYS_memfd_create, "fuzz_coff", 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<std::size_t>(n);
rem -= static_cast<std::size_t>(n);
}
char path[64];
std::snprintf(path, sizeof(path), "/proc/self/fd/%d", fd);
(void)voidlibc::voidlink::coff::parse_coff_object(path);
::close(fd);
return 0;
}