summaryrefslogtreecommitdiff
path: root/tomlplusplus/fuzzing
diff options
context:
space:
mode:
authorMehmet Samet Duman <yongdohyun@projecttick.org>2026-04-02 18:44:05 +0300
committerMehmet Samet Duman <yongdohyun@projecttick.org>2026-04-02 18:44:05 +0300
commit0b24459ac12b6cf9fd5a401d647796ca254a8fa8 (patch)
treef2fd66e2476976a51e2a51330fd95dc6e87b24c1 /tomlplusplus/fuzzing
parentb85e90fc3480da0e6a48da73201a0b22488cc650 (diff)
parent1c8b7466e4946fcc3bf20484c0e1d001202cca5a (diff)
downloadProject-Tick-0b24459ac12b6cf9fd5a401d647796ca254a8fa8.tar.gz
Project-Tick-0b24459ac12b6cf9fd5a401d647796ca254a8fa8.zip
Add 'tomlplusplus/' from commit '1c8b7466e4946fcc3bf20484c0e1d001202cca5a'
git-subtree-dir: tomlplusplus git-subtree-mainline: b85e90fc3480da0e6a48da73201a0b22488cc650 git-subtree-split: 1c8b7466e4946fcc3bf20484c0e1d001202cca5a
Diffstat (limited to 'tomlplusplus/fuzzing')
-rw-r--r--tomlplusplus/fuzzing/CMakeLists.txt31
-rwxr-xr-xtomlplusplus/fuzzing/build.sh43
-rw-r--r--tomlplusplus/fuzzing/toml_fuzzer.cpp41
3 files changed, 115 insertions, 0 deletions
diff --git a/tomlplusplus/fuzzing/CMakeLists.txt b/tomlplusplus/fuzzing/CMakeLists.txt
new file mode 100644
index 0000000000..1e62a54a13
--- /dev/null
+++ b/tomlplusplus/fuzzing/CMakeLists.txt
@@ -0,0 +1,31 @@
+# Utilized by OSSFuzz to build the harness(es) for continuous fuzz-testing
+# OSSFuzz defines the following environment variables, that this target relies upon:
+# CXX, CFLAGS, LIB_FUZZING_ENGINE, OUT
+cmake_minimum_required(VERSION 3.14)
+
+project(Fuzzer LANGUAGES CXX)
+
+include(../cmake/project-is-top-level.cmake)
+
+add_definitions(-DNDEBUG) # Do not want assertions
+
+if (DEFINED ENV{CFLAGS})
+ set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} $ENV{CFLAGS}")
+endif ()
+if (DEFINED ENV{CXXFLAGS})
+ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} $ENV{CXXFLAGS}")
+endif ()
+
+if(PROJECT_IS_TOP_LEVEL)
+ find_package(tomlplusplus REQUIRED)
+endif()
+
+add_executable(toml_fuzzer toml_fuzzer.cpp)
+target_link_libraries(toml_fuzzer PRIVATE tomlplusplus::tomlplusplus $ENV{LIB_FUZZING_ENGINE})
+target_compile_features(toml_fuzzer PRIVATE cxx_std_17)
+
+if (DEFINED ENV{OUT})
+ install(TARGETS toml_fuzzer DESTINATION $ENV{OUT})
+else ()
+ message(WARNING "Cannot install if $OUT is not defined!")
+endif () \ No newline at end of file
diff --git a/tomlplusplus/fuzzing/build.sh b/tomlplusplus/fuzzing/build.sh
new file mode 100755
index 0000000000..3fce82ae50
--- /dev/null
+++ b/tomlplusplus/fuzzing/build.sh
@@ -0,0 +1,43 @@
+cd $SRC/tomlplusplus
+mkdir -p build
+cmake -S . -B build -DBUILD_FUZZER=ON && cmake --build build --target install
+
+# Build the corpus using the existing toml files in the source
+mkdir -p corpus
+find $SRC/tomlplusplus -name "*.toml" -exec cp {} corpus \;
+zip -q -j $OUT/toml_fuzzer_seed_corpus.zip corpus/*
+
+# Build unit test
+clang++ -std=c++17 -O2 -DUSE_VENDORED_LIBS=1 \
+ -Iinclude -Itests \
+ tests/at_path.cpp \
+ tests/conformance_burntsushi_invalid.cpp \
+ tests/conformance_burntsushi_valid.cpp \
+ tests/conformance_iarna_invalid.cpp \
+ tests/conformance_iarna_valid.cpp \
+ tests/formatters.cpp \
+ tests/for_each.cpp \
+ tests/impl_toml.cpp \
+ tests/main.cpp \
+ tests/manipulating_arrays.cpp \
+ tests/manipulating_parse_result.cpp \
+ tests/manipulating_tables.cpp \
+ tests/manipulating_values.cpp \
+ tests/parsing_arrays.cpp \
+ tests/parsing_booleans.cpp \
+ tests/parsing_comments.cpp \
+ tests/parsing_dates_and_times.cpp \
+ tests/parsing_floats.cpp \
+ tests/parsing_integers.cpp \
+ tests/parsing_key_value_pairs.cpp \
+ tests/parsing_spec_example.cpp \
+ tests/parsing_strings.cpp \
+ tests/parsing_tables.cpp \
+ tests/path.cpp \
+ tests/tests.cpp \
+ tests/user_feedback.cpp \
+ tests/using_iterators.cpp \
+ tests/visit.cpp \
+ tests/windows_compat.cpp \
+ -o unit_tests \
+ -pthread
diff --git a/tomlplusplus/fuzzing/toml_fuzzer.cpp b/tomlplusplus/fuzzing/toml_fuzzer.cpp
new file mode 100644
index 0000000000..2b657f0fec
--- /dev/null
+++ b/tomlplusplus/fuzzing/toml_fuzzer.cpp
@@ -0,0 +1,41 @@
+#include <cstdint>
+#include <fuzzer/FuzzedDataProvider.h>
+
+#include <toml++/toml.hpp>
+
+enum class SerializationTest
+{
+ NONE = 0,
+ JSON,
+ YAML,
+ TOML,
+ kMaxValue = TOML
+};
+
+extern "C" int LLVMFuzzerTestOneInput(const std::uint8_t* data, const std::size_t size)
+{
+ FuzzedDataProvider fdp{data, size};
+ try
+ {
+ const toml::table tbl = toml::parse(fdp.ConsumeRandomLengthString());
+
+ switch (fdp.ConsumeEnum<SerializationTest>())
+ {
+ case SerializationTest::JSON:
+ static_cast<void>(toml::json_formatter{tbl});
+ break;
+ case SerializationTest::YAML:
+ static_cast<void>(toml::yaml_formatter{tbl});
+ break;
+ case SerializationTest::TOML:
+ static_cast<void>(toml::toml_formatter{tbl});
+ default:
+ break;
+ }
+ }
+ catch (const toml::parse_error&)
+ {
+ return -1;
+ }
+ return 0;
+}