Jonathan Rudenberg | 7db7d5b | 2018-01-13 19:51:07 -0500 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | # SPDX-License-Identifier: LGPL-2.1+ |
| 3 | # |
| 4 | # Copyright 2017 Jonathan Rudenberg |
| 5 | # |
| 6 | # systemd is free software; you can redistribute it and/or modify it |
| 7 | # under the terms of the GNU Lesser General Public License as published by |
| 8 | # the Free Software Foundation; either version 2.1 of the License, or |
| 9 | # (at your option) any later version. |
| 10 | # |
| 11 | # systemd is distributed in the hope that it will be useful, but |
| 12 | # WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 14 | # Lesser General Public License for more details. |
| 15 | # |
| 16 | # You should have received a copy of the GNU Lesser General Public License |
| 17 | # along with systemd; If not, see <http://www.gnu.org/licenses/>. |
| 18 | |
| 19 | set -ex |
| 20 | |
| 21 | export LC_CTYPE=C.UTF-8 |
| 22 | |
Jonathan Rudenberg | 31e57a3 | 2018-01-16 10:25:43 -0500 | [diff] [blame] | 23 | SANITIZER=${SANITIZER:-address -fsanitize-address-use-after-scope} |
| 24 | flags="-O1 -fno-omit-frame-pointer -gline-tables-only -DFUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION -fsanitize=$SANITIZER -fsanitize-coverage=trace-pc-guard,trace-cmp" |
| 25 | |
| 26 | export CFLAGS=${CFLAGS:-$flags} |
| 27 | export CXXFLAGS=${CXXFLAGS:-$flags} |
| 28 | export CC=${CC:-clang} |
| 29 | export CXX=${CXX:-clang++} |
| 30 | export WORK=${WORK:-$(pwd)} |
| 31 | export OUT=${OUT:-$(pwd)/out} |
| 32 | mkdir -p $OUT |
| 33 | |
Jonathan Rudenberg | 7d941c0 | 2018-01-16 08:36:56 -0500 | [diff] [blame] | 34 | build=$WORK/build |
| 35 | rm -rf $build |
| 36 | mkdir -p $build |
| 37 | |
Jonathan Rudenberg | 31e57a3 | 2018-01-16 10:25:43 -0500 | [diff] [blame] | 38 | fuzzflag="oss-fuzz=true" |
| 39 | if [ -z "$FUZZING_ENGINE" ]; then |
| 40 | fuzzflag="llvm-fuzz=true" |
| 41 | fi |
| 42 | |
| 43 | meson $build -D$fuzzflag -Db_lundef=false |
Jonathan Rudenberg | 7d941c0 | 2018-01-16 08:36:56 -0500 | [diff] [blame] | 44 | ninja -C $build fuzzers |
Jonathan Rudenberg | 7db7d5b | 2018-01-13 19:51:07 -0500 | [diff] [blame] | 45 | |
| 46 | # get DNS packet corpus |
Jonathan Rudenberg | 7d941c0 | 2018-01-16 08:36:56 -0500 | [diff] [blame] | 47 | df=$build/dns-fuzzing |
Jonathan Rudenberg | 7db7d5b | 2018-01-13 19:51:07 -0500 | [diff] [blame] | 48 | git clone --depth 1 https://github.com/CZ-NIC/dns-fuzzing $df |
| 49 | zip -jqr $OUT/fuzz-dns-packet_seed_corpus.zip $df/packet |
| 50 | |
| 51 | mkdir -p $OUT/src/shared |
Jonathan Rudenberg | 7d941c0 | 2018-01-16 08:36:56 -0500 | [diff] [blame] | 52 | mv $build/src/shared/libsystemd-shared-*.so $OUT/src/shared |
Jonathan Rudenberg | 7db7d5b | 2018-01-13 19:51:07 -0500 | [diff] [blame] | 53 | |
Jonathan Rudenberg | 7d941c0 | 2018-01-16 08:36:56 -0500 | [diff] [blame] | 54 | find $build -maxdepth 1 -type f -executable -name "fuzz-*" -exec mv {} $OUT \; |
Jonathan Rudenberg | 31e57a3 | 2018-01-16 10:25:43 -0500 | [diff] [blame] | 55 | cp src/fuzz/*.options $OUT |