Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
vanhauser-thc committed Oct 7, 2023
1 parent 278e74e commit 8c57315
Show file tree
Hide file tree
Showing 5 changed files with 125 additions and 2 deletions.
2 changes: 1 addition & 1 deletion fuzzers/aflplusplus_early/builder.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ RUN apt-get update && \
gcc-$(gcc --version|head -n1|sed 's/\..*//'|sed 's/.* //')-plugin-dev \
libstdc++-$(gcc --version|head -n1|sed 's/\..*//'|sed 's/.* //')-dev

RUN cd / && https://apt.llvm.org/llvm.sh && chmod +x llvm.sh && ./llvm.sh 17
RUN cd / && wget https://apt.llvm.org/llvm.sh && chmod +x llvm.sh && ./llvm.sh 17
ENV LLVM_CONFIG=llvm-config-17

# Download afl++.
Expand Down
2 changes: 1 addition & 1 deletion fuzzers/aflplusplus_llvm17/builder.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ RUN apt-get update && \
gcc-$(gcc --version|head -n1|sed 's/\..*//'|sed 's/.* //')-plugin-dev \
libstdc++-$(gcc --version|head -n1|sed 's/\..*//'|sed 's/.* //')-dev

RUN cd / && https://apt.llvm.org/llvm.sh && chmod +x /llvm.sh && /llvm.sh 17
RUN cd / && wget https://apt.llvm.org/llvm.sh && chmod +x /llvm.sh && /llvm.sh 17
ENV LLVM_CONFIG=llvm-config-17

# Download afl++.
Expand Down
36 changes: 36 additions & 0 deletions fuzzers/honggfuzz/builder.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# Copyright 2020 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.

ARG parent_image
FROM $parent_image

# honggfuzz requires libfd and libunwid.
RUN apt-get update -y && \
apt-get install -y \
libbfd-dev \
libunwind-dev \
libblocksruntime-dev \
liblzma-dev

# Download honggfuz version 2.3.1 + 0b4cd5b1c4cf26b7e022dc1deb931d9318c054cb
# Set CFLAGS use honggfuzz's defaults except for -mnative which can build CPU
# dependent code that may not work on the machines we actually fuzz on.
# Create an empty object file which will become the FUZZER_LIB lib (since
# honggfuzz doesn't need this when hfuzz-clang(++) is used).
RUN git clone https://github.com/google/honggfuzz.git /honggfuzz && \
cd /honggfuzz && \
git checkout oss-fuzz && \
CFLAGS="-O3 -funroll-loops" make && \
touch empty_lib.c && \
cc -c -o empty_lib.o empty_lib.c
69 changes: 69 additions & 0 deletions fuzzers/honggfuzz/fuzzer.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
# Copyright 2020 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.
"""Integration code for Honggfuzz fuzzer."""

import os
import shutil
import subprocess

from fuzzers import utils


def build():
"""Build benchmark."""
# honggfuzz doesn't need additional libraries when code is compiled
# with hfuzz-clang(++)
os.environ['CC'] = '/honggfuzz/hfuzz_cc/hfuzz-clang'
os.environ['CXX'] = '/honggfuzz/hfuzz_cc/hfuzz-clang++'
os.environ['FUZZER_LIB'] = '/honggfuzz/empty_lib.o'

utils.build_benchmark()

print('[post_build] Copying honggfuzz to $OUT directory')
# Copy over honggfuzz's main fuzzing binary.
shutil.copy('/honggfuzz/honggfuzz', os.environ['OUT'])


def fuzz(input_corpus, output_corpus, target_binary):
"""Run fuzzer."""
# Seperate out corpus and crash directories as sub-directories of
# |output_corpus| to avoid conflicts when corpus directory is reloaded.
crashes_dir = os.path.join(output_corpus, 'crashes')
output_corpus = os.path.join(output_corpus, 'corpus')
os.makedirs(crashes_dir)
os.makedirs(output_corpus)

print('[fuzz] Running target with honggfuzz')
command = [
'./honggfuzz',
'--persistent',
'--rlimit_rss',
'2048',
'--sanitizers_del_report=true',
'--input',
input_corpus,
'--output',
output_corpus,

# Store crashes along with corpus for bug based benchmarking.
'--crashdir',
crashes_dir,
]
dictionary_path = utils.get_dictionary_path(target_binary)
if dictionary_path:
command.extend(['--dict', dictionary_path])
command.extend(['--', target_binary])

print('[fuzz] Running command: ' + ' '.join(command))
subprocess.check_call(command)
18 changes: 18 additions & 0 deletions fuzzers/honggfuzz/runner.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Copyright 2020 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/fuzzbench/base-image

# honggfuzz requires libfd and libunwid
RUN apt-get update -y && apt-get install -y libbfd-dev libunwind-dev

0 comments on commit 8c57315

Please sign in to comment.