Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

initial nokogiri libgumbo integration #11004

Merged
merged 7 commits into from
Oct 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions projects/nokogiri/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Copyright 2023 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
###############################################################################

FROM gcr.io/oss-fuzz-base/base-builder
RUN apt-get update && apt-get --no-install-recommends install -y build-essential make curl wget

RUN git clone https://github.com/sparklemotion/nokogiri.git

RUN wget https://github.com/fuzzy-boiii23a/oss-fuzz-corpus/raw/main/nokogiri_corpus.zip

COPY build.sh parse_fuzzer.cc gumbo.dict $SRC/
68 changes: 68 additions & 0 deletions projects/nokogiri/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
# Copyright 2023 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
###############################################################################

export SANITIZER_OPTS=""
export SANITIZER_LINK=""

if [ "$FUZZING_ENGINE" = "centipede" ]
then
export CXXFLAGS="-fsanitize-coverage=trace-pc-guard,pc-table,trace-cmp -DFUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION -fno-builtin -gline-tables-only"
export CFLAGS="-fsanitize-coverage=trace-pc-guard,pc-table,trace-cmp -DFUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION -fno-builtin -gline-tables-only"
export ENGINE_LINK="$LIB_FUZZING_ENGINE -lc++"
fi
if [ "$FUZZING_ENGINE" = "libfuzzer" ]
then
export CXXFLAGS="-fsanitize=fuzzer-no-link"
export CFLAGS="-fsanitize=fuzzer-no-link"
export ENGINE_LINK="$(find $(llvm-config --libdir) -name libclang_rt.fuzzer-x86_64.a | head -1)"
fi
if [ "$FUZZING_ENGINE" = "honggfuzz" ]
then
export CXXFLAGS="-fsanitize-coverage=trace-pc-guard,indirect-calls,trace-cmp"
export CFLAGS="-fsanitize-coverage=trace-pc-guard,indirect-calls,trace-cmp"
export ENGINE_LINK="$(find . -name honggfuzz.a)"
fi
if [ "$FUZZING_ENGINE" = "afl" ]
then
export CXXFLAGS="-fsanitize=fuzzer-no-link -fsanitize-coverage=trace-pc-guard,indirect-calls,trace-cmp"
export CFLAGS="-fsanitize=fuzzer-no-link -fsanitize-coverage=trace-pc-guard,indirect-calls,trace-cmp"
export ENGINE_LINK="$(find . -name libAFLDriver.a | head -1) $(find . -name afl-compiler-rt-64.o | head -1)"
fi

if [ "$SANITIZER" = "undefined" ]
then
export SANITIZER_OPTS="-fsanitize=undefined"
export SANITIZER_LINK="$(find $(llvm-config --libdir) -name libclang_rt.ubsan_standalone_cxx-x86_64.a | head -1)"
fi
if [ "$SANITIZER" = "address" ]
then
export SANITIZER_OPTS="-fsanitize=address"
export SANITIZER_LINK="$(find $(llvm-config --libdir) -name libclang_rt.asan_cxx-x86_64.a | head -1)"
fi
if [ "$SANITIZER" = "coverage" ]
then
export SANITIZER_OPTS="-g -fprofile-instr-generate -fcoverage-mapping"
export SANITIZER_LINK=""
fi


export CXXFLAGS="-O0 $CXXFLAGS $SANITIZER_OPTS"
export CFLAGS="-O0 $CFLAGS $SANITIZER_OPTS"
cd nokogiri/gumbo-parser/src && make clean && make && cd -
$CXX $CXXFLAGS -o parse_fuzzer parse_fuzzer.cc nokogiri/gumbo-parser/src/libgumbo.a $ENGINE_LINK $SANITIZER_LINK
mv parse_fuzzer $OUT/parse_fuzzer
mv gumbo.dict $OUT/parse_fuzzer.dict
mv nokogiri_corpus.zip $OUT/parse_fuzzer_seed_corpus.zip
Loading