1#!/bin/bash -e 2# 3# Copyright(c) 2017-2018 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# This file is part of libpsl. 24 25trap ctrl_c INT 26 27ctrl_c() { 28 ./${fuzzer} -merge=1 ${fuzzer}.in ${fuzzer}.new 29 rm -rf ${fuzzer}.new 30} 31 32if test -z "$1"; then 33 echo "Usage: $0 <fuzzer target>" 34 echo "Example: $0 libpsl_idn2_fuzzer" 35 exit 1 36fi 37 38fuzzer=$1 39workers=$(($(nproc) - 1)) 40jobs=$workers 41 42case $fuzzer in 43 libpsl_idn2_*) 44 cfile="libpsl_"$(echo $fuzzer|cut -d'_' -f3-)".c" 45 XLIBS="-lidn2 -lunistring";; 46 libpsl_idn_*) 47 cfile="libpsl_"$(echo $fuzzer|cut -d'_' -f3-)".c" 48 XLIBS="-lidn -lunistring";; 49 libpsl_icu_*) 50 cfile="libpsl_"$(echo $fuzzer|cut -d'_' -f3-)".c" 51 XLIBS="-licuuc -licudata";; 52 libpsl_*) 53 cfile=${fuzzer}.c 54 XLIBS= 55esac 56 57clang-5.0 \ 58 $CFLAGS -Og -g -I../include -I.. \ 59 ${cfile} -o ${fuzzer} \ 60 -Wl,-Bstatic ../src/.libs/libpsl.a -lFuzzer \ 61 -Wl,-Bdynamic $XLIBS -lclang-5.0 -lpthread -lm -lstdc++ 62 63if test -n "$BUILD_ONLY"; then 64 exit 0 65fi 66 67# create directory for NEW test corpora (covering new areas of code) 68mkdir -p ${fuzzer}.new 69 70if test -f ${fuzzer}.dict; then 71 ./${fuzzer} -dict=${fuzzer}.dict ${fuzzer}.new ${fuzzer}.in -jobs=$jobs -workers=$workers 72else 73 ./${fuzzer} ${fuzzer}.new ${fuzzer}.in -jobs=$jobs -workers=$workers 74fi 75 76exit 0 77