Fuzzing Zig Code Using AFL++

# · ✸ 85 · 💬 20 · 2 years ago · www.ryanliptak.com · zdw · 📷
After using code coverage information and real-world files to improve an audio metadata parser I am writing in Zig, the next step was to fuzz test it in order to ensure that crashes, memory leaks, etc were ironed out as much as possible. The problem was that I had no idea how to fuzz Zig code. My idea was to compile the Zig code as a static library with LTO enabled, and then use the afl-clang-lto compiler to compile a normal C program that calls the Zig library. Instead of linking the Zig code in as a static library, I wondered if it was possible to compile the Zig code to an object file and then use afl-clang-lto to transform the object file into an executable, thereby getting the instrumentation without having to compile any C code. O` const fuzz compile = b.addSystemCommand(&[ ][]const u8 ); // Add the output path to afl-clang-lto's args fuzz compile. Fuzz executable name); // Add a top-level step that compiles and installs the fuzz executable const fuzz compile run = b.step("Fuzz", "Build executable for fuzz testing using afl-clang-lto"); fuzz compile run. Debug); // Only install fuzz-debug when the fuzz step is run const install fuzz debug exe = b.addInstallArtifact(fuzz debug exe); fuzz compile run.
Fuzzing Zig Code Using AFL++



Send Feedback | WebAssembly Version (beta)