Skip to content

Commit

Permalink
make independent libfuzzers (#38)
Browse files Browse the repository at this point in the history
* make independent libfuzzer for parser and lexer. Setup cmake to make future libfuzzers easy to add

* upgrade the build
  • Loading branch information
farzonl authored Apr 23, 2023
1 parent 1635d2c commit a772121
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 15 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/cmake-libfuzzer.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`
- 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`
13 changes: 9 additions & 4 deletions fuzz/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
)
)
endforeach()
7 changes: 0 additions & 7 deletions fuzz/fuzzTest.cpp → fuzz/lexerFuzzer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -12,19 +11,13 @@ 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;
}
std::string sLine(cLine, len);
try {
LexerFuzzTest(sLine);
ParserFuzzTest(sLine);
} catch (...) {
return -1;
}
Expand Down
23 changes: 23 additions & 0 deletions fuzz/parserFuzzer.cpp
Original file line number Diff line number Diff line change
@@ -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;
}
2 changes: 1 addition & 1 deletion src/lib/Version/version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.0.7
0.0.8

0 comments on commit a772121

Please sign in to comment.