From 55d63582ee355d25a5e2276884e6ca0b89c8138e Mon Sep 17 00:00:00 2001 From: Sergey Bronnikov Date: Thu, 27 Apr 2023 17:15:29 +0300 Subject: [PATCH] [lua][waiting for upstream]: add new fuzzers (#10092) - fix indentation in config - add me to auto_ccs - add new fuzzers --- projects/lua/Dockerfile | 8 ++++- projects/lua/build.sh | 62 +++++++++++++++++++++++++++++++++++++++ projects/lua/project.yaml | 1 + 3 files changed, 70 insertions(+), 1 deletion(-) diff --git a/projects/lua/Dockerfile b/projects/lua/Dockerfile index 054ce66c6..a74194a54 100644 --- a/projects/lua/Dockerfile +++ b/projects/lua/Dockerfile @@ -15,8 +15,14 @@ ################################################################################ FROM gcr.io/oss-fuzz-base/base-builder -RUN apt-get update && apt-get install -y libreadline-dev +RUN apt-get update && apt-get install -y \ + build-essential ninja-build cmake make \ + zlib1g-dev libreadline-dev libunwind-dev RUN git clone https://github.com/lua/lua +RUN git clone https://github.com/ligurio/lua-c-api-tests testdir +WORKDIR testdir +RUN git clone --depth 1 --jobs $(nproc) https://github.com/ligurio/lua-c-api-corpus corpus_dir +COPY build.sh testdir/ WORKDIR $SRC COPY build.sh $SRC/ COPY fuzz_lua.c $SRC/ diff --git a/projects/lua/build.sh b/projects/lua/build.sh index 8b21ce1c5..2a3b4445b 100755 --- a/projects/lua/build.sh +++ b/projects/lua/build.sh @@ -26,3 +26,65 @@ make cp ../fuzz_lua.c . $CC $CFLAGS -c fuzz_lua.c -o fuzz_lua.o $CXX $CXXFLAGS $LIB_FUZZING_ENGINE fuzz_lua.o -o $OUT/fuzz_lua ./liblua.a + +cd $SRC/testdir + +# Avoid compilation issue due to some undefined references. They are defined in +# libc++ and used by Centipede so -lc++ needs to come after centipede's lib. +if [[ $FUZZING_ENGINE == centipede ]] +then + sed -i \ + '/$ENV{LIB_FUZZING_ENGINE}/a \ \ \ \ \ \ \ \ -lc++' \ + tests/CMakeLists.txt +fi + +# Clean up potentially persistent build directory. +[[ -e $SRC/testdir/build ]] && rm -rf $SRC/testdir/build + +case $SANITIZER in + address) SANITIZERS_ARGS="-DENABLE_ASAN=ON" ;; + undefined) SANITIZERS_ARGS="-DENABLE_UBSAN=ON" ;; + *) SANITIZERS_ARGS="" ;; +esac + +: ${LD:="${CXX}"} +: ${LDFLAGS:="${CXXFLAGS}"} # to make sure we link with sanitizer runtime + +cmake_args=( + -DUSE_LUA=ON + -DOSS_FUZZ=ON + $SANITIZERS_ARGS + + # C compiler + -DCMAKE_C_COMPILER="${CC}" + -DCMAKE_C_FLAGS="${CFLAGS}" + + # C++ compiler + -DCMAKE_CXX_COMPILER="${CXX}" + -DCMAKE_CXX_FLAGS="${CXXFLAGS}" + + # Linker + -DCMAKE_LINKER="${LD}" + -DCMAKE_EXE_LINKER_FLAGS="${LDFLAGS}" + -DCMAKE_MODULE_LINKER_FLAGS="${LDFLAGS}" + -DCMAKE_SHARED_LINKER_FLAGS="${LDFLAGS}" +) + +# To deal with a host filesystem from inside of container. +git config --global --add safe.directory '*' + +# Build the project and fuzzers. +[[ -e build ]] && rm -rf build +cmake "${cmake_args[@]}" -S . -B build -G Ninja +cmake --build build --parallel + +# Archive and copy to $OUT seed corpus if the build succeeded. +for f in $(find build/tests/ -name '*_test' -type f); +do + name=$(basename $f); + module=$(echo $name | sed 's/_test//') + corpus_dir="corpus_dir/$module" + echo "Copying for $module"; + cp $f $OUT/ + [[ -e $corpus_dir ]] && zip -j $OUT/"$module"_seed_corpus.zip $corpus_dir/* +done diff --git a/projects/lua/project.yaml b/projects/lua/project.yaml index 9a4b0dd3a..850891c2d 100644 --- a/projects/lua/project.yaml +++ b/projects/lua/project.yaml @@ -4,4 +4,5 @@ primary_contact: "roberto@inf.puc-rio.br" auto_ccs: - "fuzz@lua.org" - "david@adalogics.com" + - "estetus@gmail.com" main_repo: 'https://github.com/lua/lua'