commit f720043183d3ed8002ca7425ce0d7ba548dd6a52
parent 959b2f722556047d6fc53761380e229006fdb92e
Author: Frederic Cambus <fred@statdns.com>
Date: Thu, 22 Oct 2020 10:37:50 +0200
Add LibFuzzer-based fuzzers for each supported format.
Diffstat:
8 files changed, 161 insertions(+), 0 deletions(-)
diff --git a/fuzz/CMakeLists.txt b/fuzz/CMakeLists.txt
@@ -0,0 +1,35 @@
+cmake_minimum_required (VERSION 2.6)
+
+set(CMAKE_C_COMPILER clang)
+
+project (fuzz C)
+
+# Ansilove library
+find_path(ANSILOVE_INCLUDE_DIRS ansilove.h)
+find_library(ANSILOVE_LIBRARIES NAMES ansilove REQUIRED)
+include_directories(${ANSILOVE_INCLUDE_DIRS})
+
+set(SRC_ANSI ansi.c)
+set(SRC_ARTWORX artworx.c)
+set(SRC_BINARY binary.c)
+set(SRC_ICEDRAW icedraw.c)
+set(SRC_PCBOARD pcboard.c)
+set(SRC_TUNDRA tundra.c)
+set(SRC_XBIN xbin.c)
+
+add_definitions(-Wall -Wextra -std=c99 -pedantic -fsanitize=fuzzer)
+add_executable(ansi ${SRC_ANSI})
+add_executable(artworx ${SRC_ANSI})
+add_executable(binary ${SRC_BINARY})
+add_executable(icedraw ${SRC_BINARY})
+add_executable(pcboard ${SRC_BINARY})
+add_executable(tundra ${SRC_BINARY})
+add_executable(xbin ${SRC_BINARY})
+
+target_link_libraries(ansi ${ANSILOVE_LIBRARIES} -fsanitize=fuzzer)
+target_link_libraries(artworx ${ANSILOVE_LIBRARIES} -fsanitize=fuzzer)
+target_link_libraries(binary ${ANSILOVE_LIBRARIES} -fsanitize=fuzzer)
+target_link_libraries(icedraw ${ANSILOVE_LIBRARIES} -fsanitize=fuzzer)
+target_link_libraries(pcboard ${ANSILOVE_LIBRARIES} -fsanitize=fuzzer)
+target_link_libraries(tundra ${ANSILOVE_LIBRARIES} -fsanitize=fuzzer)
+target_link_libraries(xbin ${ANSILOVE_LIBRARIES} -fsanitize=fuzzer)
diff --git a/fuzz/ansi.c b/fuzz/ansi.c
@@ -0,0 +1,18 @@
+#include <ansilove.h>
+
+int
+LLVMFuzzerTestOneInput(uint8_t *data, size_t size)
+{
+ struct ansilove_ctx ctx;
+ struct ansilove_options options;
+
+ ansilove_init(&ctx, &options);
+
+ ctx.buffer = data;
+ ctx.length = size;
+
+ ansilove_ansi(&ctx, &options);
+
+ ansilove_clean(&ctx);
+ return 0;
+}
diff --git a/fuzz/artworx.c b/fuzz/artworx.c
@@ -0,0 +1,18 @@
+#include <ansilove.h>
+
+int
+LLVMFuzzerTestOneInput(uint8_t *data, size_t size)
+{
+ struct ansilove_ctx ctx;
+ struct ansilove_options options;
+
+ ansilove_init(&ctx, &options);
+
+ ctx.buffer = data;
+ ctx.length = size;
+
+ ansilove_artworx(&ctx, &options);
+
+ ansilove_clean(&ctx);
+ return 0;
+}
diff --git a/fuzz/binary.c b/fuzz/binary.c
@@ -0,0 +1,18 @@
+#include <ansilove.h>
+
+int
+LLVMFuzzerTestOneInput(uint8_t *data, size_t size)
+{
+ struct ansilove_ctx ctx;
+ struct ansilove_options options;
+
+ ansilove_init(&ctx, &options);
+
+ ctx.buffer = data;
+ ctx.length = size;
+
+ ansilove_binary(&ctx, &options);
+
+ ansilove_clean(&ctx);
+ return 0;
+}
diff --git a/fuzz/icedraw.c b/fuzz/icedraw.c
@@ -0,0 +1,18 @@
+#include <ansilove.h>
+
+int
+LLVMFuzzerTestOneInput(uint8_t *data, size_t size)
+{
+ struct ansilove_ctx ctx;
+ struct ansilove_options options;
+
+ ansilove_init(&ctx, &options);
+
+ ctx.buffer = data;
+ ctx.length = size;
+
+ ansilove_icedraw(&ctx, &options);
+
+ ansilove_clean(&ctx);
+ return 0;
+}
diff --git a/fuzz/pcboard.c b/fuzz/pcboard.c
@@ -0,0 +1,18 @@
+#include <ansilove.h>
+
+int
+LLVMFuzzerTestOneInput(uint8_t *data, size_t size)
+{
+ struct ansilove_ctx ctx;
+ struct ansilove_options options;
+
+ ansilove_init(&ctx, &options);
+
+ ctx.buffer = data;
+ ctx.length = size;
+
+ ansilove_pcboard(&ctx, &options);
+
+ ansilove_clean(&ctx);
+ return 0;
+}
diff --git a/fuzz/tundra.c b/fuzz/tundra.c
@@ -0,0 +1,18 @@
+#include <ansilove.h>
+
+int
+LLVMFuzzerTestOneInput(uint8_t *data, size_t size)
+{
+ struct ansilove_ctx ctx;
+ struct ansilove_options options;
+
+ ansilove_init(&ctx, &options);
+
+ ctx.buffer = data;
+ ctx.length = size;
+
+ ansilove_tundra(&ctx, &options);
+
+ ansilove_clean(&ctx);
+ return 0;
+}
diff --git a/fuzz/xbin.c b/fuzz/xbin.c
@@ -0,0 +1,18 @@
+#include <ansilove.h>
+
+int
+LLVMFuzzerTestOneInput(uint8_t *data, size_t size)
+{
+ struct ansilove_ctx ctx;
+ struct ansilove_options options;
+
+ ansilove_init(&ctx, &options);
+
+ ctx.buffer = data;
+ ctx.length = size;
+
+ ansilove_xbin(&ctx, &options);
+
+ ansilove_clean(&ctx);
+ return 0;
+}