| 1 |
#!/bin/sh -eu |
| 2 |
|
| 3 |
# Copyright (c) 2017-2025 Tim Ruehsen |
| 4 |
# |
| 5 |
# Permission is hereby granted, free of charge, to any person obtaining a |
| 6 |
# copy of this software and associated documentation files (the "Software"), |
| 7 |
# to deal in the Software without restriction, including without limitation |
| 8 |
# the rights to use, copy, modify, merge, publish, distribute, sublicense, |
| 9 |
# and/or sell copies of the Software, and to permit persons to whom the |
| 10 |
# Software is furnished to do so, subject to the following conditions: |
| 11 |
# |
| 12 |
# The above copyright notice and this permission notice shall be included in |
| 13 |
# all copies or substantial portions of the Software. |
| 14 |
# |
| 15 |
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 16 |
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 17 |
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 18 |
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 19 |
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
| 20 |
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
| 21 |
# DEALINGS IN THE SOFTWARE. |
| 22 |
|
| 23 |
# First step: In the top directory execute |
| 24 |
# export CC=clang-5.0 |
| 25 |
# export CFLAGS="-O1 -fno-omit-frame-pointer -gline-tables-only -DFUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION -fsanitize=address -fsanitize-address-use-after-scope -fsanitize-coverage=trace-pc-guard,trace-cmp" |
| 26 |
# ./configure --enable-static --disable-gtk-doc --enable-runtime=libidn2 --enable-builtin=libidn2 |
| 27 |
# make clean |
| 28 |
# make -j$(nproc) LIB_FUZZING_ENGINE="-lFuzzer" |
| 29 |
# cd fuzz |
| 30 |
# make -j$(nproc) check |
| 31 |
|
| 32 |
# |
| 33 |
# Read the docs at https://github.com/google/oss-fuzz/blob/master/docs/corpora.md |
| 34 |
# then install 'google-cloud-sdk' and execute 'gcloud init'. |
| 35 |
# Now 'gsutil' should be ready to use. |
| 36 |
|
| 37 |
if test -z "$1"; then |
| 38 |
echo "Usage: $0 <fuzzer target>" |
| 39 |
echo "Example: $0 libidn2_to_ascii_8z_fuzzer" |
| 40 |
exit 1 |
| 41 |
fi |
| 42 |
|
| 43 |
fuzzer=$1 |
| 44 |
project=$(echo $1 | cut -d'_' -f1) |
| 45 |
|
| 46 |
# sync/copy the OSS-Fuzz corpora into the .new directory |
| 47 |
mkdir -p ${fuzzer}.new |
| 48 |
cp -p ${fuzzer}.in/* ${fuzzer}.new |
| 49 |
gsutil cp $(gsutil ls gs://${project}-backup.clusterfuzz-external.appspot.com/corpus/libFuzzer/${fuzzer}|tail -n 1) ${fuzzer}.new |
| 50 |
(cd ${fuzzer}.new && unzip -q -f -o *.zip && rm *.zip) |
| 51 |
|
| 52 |
# create fuzzer target |
| 53 |
BUILD_ONLY=1 ./run-clang.sh ${fuzzer} |
| 54 |
|
| 55 |
# merge the corpora into the .in directory |
| 56 |
./${fuzzer} -merge=1 ${fuzzer}.in ${fuzzer}.new |
| 57 |
|
| 58 |
# now clear .new dir and put all corpora there |
| 59 |
rm -f ${fuzzer}.new/* |
| 60 |
mv ${fuzzer}.in/* ${fuzzer}.new |
| 61 |
|
| 62 |
# now merge again (optimizes number of corpora) |
| 63 |
./${fuzzer} -merge=1 ${fuzzer}.in ${fuzzer}.new |
| 64 |
|
| 65 |
echo |
| 66 |
echo "If new files have been added, 'git add' and 'git commit' them." |