mirror of
https://github.com/ghostty-org/ghostty.git
synced 2026-04-19 22:10:29 +00:00
test/fuzz-libghostty: basic afl++-based fuzzer for libghostty
This commit is contained in:
11
test/fuzz-libghostty/src/lib.zig
Normal file
11
test/fuzz-libghostty/src/lib.zig
Normal file
@@ -0,0 +1,11 @@
|
||||
const std = @import("std");
|
||||
const ghostty_vt = @import("ghostty-vt");
|
||||
|
||||
pub export fn ghostty_fuzz_parser(
|
||||
input_ptr: [*]const u8,
|
||||
input_len: usize,
|
||||
) callconv(.c) void {
|
||||
var p: ghostty_vt.Parser = .init();
|
||||
defer p.deinit();
|
||||
for (input_ptr[0..input_len]) |byte| _ = p.next(byte);
|
||||
}
|
||||
27
test/fuzz-libghostty/src/main.c
Normal file
27
test/fuzz-libghostty/src/main.c
Normal file
@@ -0,0 +1,27 @@
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
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;
|
||||
}
|
||||
Reference in New Issue
Block a user