diff --git a/pkg/afl++/afl.c b/pkg/afl++/afl.c index 838829fd9..61eb12c4a 100644 --- a/pkg/afl++/afl.c +++ b/pkg/afl++/afl.c @@ -23,7 +23,7 @@ // zig_fuzz_test() runs one fuzz iteration on the given input buffer. // The Zig object should export these. void zig_fuzz_init(); -void zig_fuzz_test(unsigned char*, ssize_t); +void zig_fuzz_test(unsigned char*, size_t); // Linker-provided symbols marking the boundaries of the __sancov_guards // section. These must be declared extern so the linker provides the actual @@ -132,7 +132,9 @@ int main(int argc, char** argv) { ? 0 : *__afl_fuzz_len; - zig_fuzz_test(buf, len); + if (len >= 0) { + zig_fuzz_test(buf, len); + } } return 0; diff --git a/test/fuzz-libghostty/src/lib.zig b/test/fuzz-libghostty/src/lib.zig index f33560317..b00f180aa 100644 --- a/test/fuzz-libghostty/src/lib.zig +++ b/test/fuzz-libghostty/src/lib.zig @@ -1,18 +1,15 @@ const std = @import("std"); const ghostty_vt = @import("ghostty-vt"); -pub export fn zig_fuzz_init() callconv(.c) void {} - -pub export fn zig_fuzz_test(buf: [*]const u8, len: isize) callconv(.c) void { - if (len <= 0) return; - ghostty_fuzz_parser(buf, @intCast(len)); +pub export fn zig_fuzz_init() callconv(.c) void { + // Nothing to do } -pub export fn ghostty_fuzz_parser( - input_ptr: [*]const u8, - input_len: usize, +pub export fn zig_fuzz_test( + buf: [*]const u8, + len: usize, ) callconv(.c) void { var p: ghostty_vt.Parser = .init(); defer p.deinit(); - for (input_ptr[0..input_len]) |byte| _ = p.next(byte); + for (buf[0..@intCast(len)]) |byte| _ = p.next(byte); } diff --git a/test/fuzz-libghostty/src/main.c b/test/fuzz-libghostty/src/main.c deleted file mode 100644 index e2f6942bb..000000000 --- a/test/fuzz-libghostty/src/main.c +++ /dev/null @@ -1,27 +0,0 @@ -#include -#include -#include - -void ghostty_fuzz_parser(const uint8_t *input, size_t input_len); - -int main(int argc, char **argv) { - uint8_t buf[4096]; - size_t len = 0; - FILE *f = stdin; - - if (argc > 1) { - f = fopen(argv[1], "rb"); - if (f == NULL) { - return 0; - } - } - - len = fread(buf, 1, sizeof(buf), f); - - if (argc > 1) { - fclose(f); - } - - ghostty_fuzz_parser(buf, len); - return 0; -}