From a7721214f055e79cbfba178aebd832ae2c222d96 Mon Sep 17 00:00:00 2001 From: Farzon Lotfi <1802579+farzonl@users.noreply.github.com> Date: Sun, 23 Apr 2023 15:58:33 -0400 Subject: [PATCH] make independent libfuzzers (#38) * make independent libfuzzer for parser and lexer. Setup cmake to make future libfuzzers easy to add * upgrade the build --- .github/workflows/cmake-libfuzzer.yml | 4 ++-- README.md | 6 +++++- fuzz/CMakeLists.txt | 13 +++++++++---- fuzz/{fuzzTest.cpp => lexerFuzzer.cpp} | 7 ------- fuzz/parserFuzzer.cpp | 23 +++++++++++++++++++++++ src/lib/Version/version.txt | 2 +- 6 files changed, 40 insertions(+), 15 deletions(-) rename fuzz/{fuzzTest.cpp => lexerFuzzer.cpp} (79%) create mode 100644 fuzz/parserFuzzer.cpp diff --git a/.github/workflows/cmake-libfuzzer.yml b/.github/workflows/cmake-libfuzzer.yml index 1aa4891..8a178d8 100644 --- a/.github/workflows/cmake-libfuzzer.yml +++ b/.github/workflows/cmake-libfuzzer.yml @@ -113,7 +113,7 @@ jobs: shell: bash run: | mkdir ${{github.workspace}}/artifacts - cp build/fuzz/${{ env.APPNAME }}Lang_FUZZ ${{github.workspace}}/artifacts + cp build/fuzz/*Fuzzer ${{github.workspace}}/artifacts pushd ${{github.workspace}} zip -r ${{ env.APPNAME }}-$(uname -s)-libfuzzers-$(uname -m).zip artifacts popd @@ -122,7 +122,7 @@ jobs: shell: powershell run: | [system.io.directory]::CreateDirectory("${{github.workspace}}/artifacts") - Copy-Item "build/fuzz/${{ env.APPNAME }}Lang_FUZZ${{ matrix.artifact_exec_ext }}" -Destination "${{github.workspace}}/artifacts" + Copy-Item "build/fuzz/${{ env.APPNAME }}*Fuzzer${{ matrix.artifact_exec_ext }}" -Destination "${{github.workspace}}/artifacts" Compress-Archive -Path ${{github.workspace}}/artifacts/* -DestinationPath ${{ env.APPNAME }}-${{matrix.artifact_os_name}}-libfuzzers-${{matrix.artifact_arch}}.zip - name: 'Upload Pull Request Artifact' uses: actions/upload-artifact@v3 diff --git a/README.md b/README.md index 1d9e2b7..67ff2fb 100644 --- a/README.md +++ b/README.md @@ -85,4 +85,8 @@ run-clang-tidy.py -p build/ -header-filter='.*' -fix -format ## Docker Build & Run freeBSD x86_64 - Build: `docker build -f Dockerfile.freebsd-cross -t warflang_freebsd:latest .` -- Run: `docker run --name freebsd_test_vm -it warflang_freebsd:latest` \ No newline at end of file +- Run: `docker run --name freebsd_test_vm -it warflang_freebsd:latest` + +## Docker Build & Run emscripten web +- Build: `docker build -f Dockerfile.emscripten -t warflang_web:latest .` +- Run: `docker run --name emsdk_test_vm -it warflang_web:latest` \ No newline at end of file diff --git a/fuzz/CMakeLists.txt b/fuzz/CMakeLists.txt index d96f81b..f32a40f 100644 --- a/fuzz/CMakeLists.txt +++ b/fuzz/CMakeLists.txt @@ -6,7 +6,11 @@ project(${CMAKE_PROJECT_NAME}_FUZZ) include_directories(${CMAKE_SOURCE_DIR}/src/lib) -add_executable(${PROJECT_NAME} fuzzTest.cpp) +set(fuzzers "lexerFuzzer;parserFuzzer" CACHE STRING "libfuzzers") +foreach(fuzzer ${fuzzers}) + add_executable(${fuzzer} ${fuzzer}.cpp) +endforeach() + #clang++ -g -fsanitize=address,fuzzer @@ -21,7 +25,8 @@ elseif(UNIX) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g") endif() - -target_link_libraries(${PROJECT_NAME} PRIVATE +foreach(fuzzer ${fuzzers}) + target_link_libraries(${fuzzer} PRIVATE WarfCore -) \ No newline at end of file + ) +endforeach() diff --git a/fuzz/fuzzTest.cpp b/fuzz/lexerFuzzer.cpp similarity index 79% rename from fuzz/fuzzTest.cpp rename to fuzz/lexerFuzzer.cpp index 0211a3e..7e0b58d 100644 --- a/fuzz/fuzzTest.cpp +++ b/fuzz/lexerFuzzer.cpp @@ -3,7 +3,6 @@ // license that can be found in the LICENSE file. #include "Syntax/Lexer.h" -#include "Syntax/Parser.h" void LexerFuzzTest(std::string &line) { Lexer lex(line); @@ -12,11 +11,6 @@ void LexerFuzzTest(std::string &line) { } } -void ParserFuzzTest(std::string &line) { - Parser parser(line); - parser.Parse(); -} - extern "C" int LLVMFuzzerTestOneInput(const char *cLine, size_t len) { if (cLine == nullptr) { return -1; @@ -24,7 +18,6 @@ extern "C" int LLVMFuzzerTestOneInput(const char *cLine, size_t len) { std::string sLine(cLine, len); try { LexerFuzzTest(sLine); - ParserFuzzTest(sLine); } catch (...) { return -1; } diff --git a/fuzz/parserFuzzer.cpp b/fuzz/parserFuzzer.cpp new file mode 100644 index 0000000..596694b --- /dev/null +++ b/fuzz/parserFuzzer.cpp @@ -0,0 +1,23 @@ +// Copyright (c) 2022 F. Lotfi All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +#include "Syntax/Parser.h" + +void ParserFuzzTest(std::string &line) { + Parser parser(line); + parser.Parse(); +} + +extern "C" int LLVMFuzzerTestOneInput(const char *cLine, size_t len) { + if (cLine == nullptr) { + return -1; + } + std::string sLine(cLine, len); + try { + ParserFuzzTest(sLine); + } catch (...) { + return -1; + } + return 0; +} diff --git a/src/lib/Version/version.txt b/src/lib/Version/version.txt index 5c4511c..7d6b3eb 100644 --- a/src/lib/Version/version.txt +++ b/src/lib/Version/version.txt @@ -1 +1 @@ -0.0.7 \ No newline at end of file +0.0.8 \ No newline at end of file