1#!/bin/bash -eu
2# Copyright 2016 Google Inc.
3#
4# Licensed under the Apache License, Version 2.0 (the "License");
5# you may not use this file except in compliance with the License.
6# You may obtain a copy of the License at
7#
8#      http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS,
12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13# See the License for the specific language governing permissions and
14# limitations under the License.
15#
16################################################################################
17
18# setup
19BUILD=$WORK/Build
20fuzz_targets=(
21    src/fe-fuzz/irssi-fuzz
22    src/fe-fuzz/server-fuzz
23    src/fe-fuzz/irc/core/event-get-params-fuzz
24    src/fe-fuzz/fe-common/core/theme-load-fuzz
25)
26
27if [ "$FUZZING_ENGINE" = honggfuzz ]; then
28    export CC="$SRC"/"$FUZZING_ENGINE"/hfuzz_cc/hfuzz-clang
29    export CXX="$SRC"/"$FUZZING_ENGINE"/hfuzz_cc/hfuzz-clang++
30fi
31
32# cleanup
33rm -rf "$BUILD"
34mkdir -p "$BUILD"
35
36# Configure the project.
37meson "$BUILD" -Dstatic-dependency=yes -Dinstall-glib=force \
38      -Dwith-fuzzer=yes -Dwith-fuzzer-lib=$LIB_FUZZING_ENGINE \
39      -Dfuzzer-link-language=cpp \
40    || ( cat "$BUILD"/meson-logs/meson-log.txt && false )
41
42# now build all fuzz targets
43ninja -C "$BUILD" -v "${fuzz_targets[@]}"
44( cd "$BUILD" && mv "${fuzz_targets[@]}" "$OUT" )
45
46git clone --depth 1 https://github.com/irssi-import/themes         theme-load-fuzz_corpus
47git clone --depth 1 https://github.com/irssi/irssi-fuzzing-corpora
48
49find theme-load-fuzz_corpus -mindepth 1 -maxdepth 1 \( -type d -o \! -name \*.theme \) -exec rm -fr {} +
50
51zip -q -j "$OUT"/theme-load-fuzz_seed_corpus.zip theme-load-fuzz_corpus/*
52zip -q -j "$OUT"/irssi-fuzz_seed_corpus.zip      irssi-fuzzing-corpora/irssi-fuzz-corpus/*
53zip -q -j "$OUT"/server-fuzz_seed_corpus.zip     irssi-fuzzing-corpora/server-fuzz-corpus/*
54
55# get tokens.txt dictionary from irssi/src/fe-fuzz/
56cp src/fe-fuzz/tokens.txt "$OUT"/server-fuzz.dict
57
58cp "$SRC"/*.options "$SRC"/*.dict "$OUT"/
59