• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/bin/bash -eu
2# Copyright 2018 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
18autoreconf -fi
19
20libqb=`find /usr/lib/ -name libqb.a -print -quit`
21protobuf=`find /usr/lib/ -name libprotobuf.a -print -quit`
22
23qb_LIBS="${libqb}" \
24  protobuf_LIBS="-pthread ${protobuf} -pthread -lpthread" \
25  ./configure --with-bundled-catch --with-bundled-pegtl \
26  --with-crypto-library=gcrypt --disable-shared
27
28fuzzers="$( cd src/Tests/Fuzzers && find -name 'fuzzer-*.cpp' |
29           sed 's/^\.\/\(fuzzer-.*\)\.cpp$/\1/g' )"
30
31make -j`nproc` src/build-config.h libusbguard.la
32make -j`nproc` -C src/Tests/Fuzzers ${fuzzers}
33
34cd src/Tests/Fuzzers
35mv ${fuzzers} "$OUT"
36
37################################################################################
38# Create seed corpora.
39################################################################################
40
41# General case:
42cd "$SRC/usbguard/src/Tests/Fuzzers"
43# fuzzer-usb-descriptor seed corpus.
44for fuzzer_name in ${fuzzers}; do
45  corpus_dir="${fuzzer_name}_corpus"
46  if [[ ! -d "$corpus_dir" ]] ; then
47    continue
48  fi
49  zip_name="$OUT/${fuzzer_name}_seed_corpus.zip"
50  rm -f "${zip_name}"
51  zip -r "${zip_name}" "${corpus_dir}"
52done
53
54# Specific cases:
55cd "$WORK"
56# fuzzer-rules seed corpus.
57fuzzer_name=fuzzer-rules
58corpus_dir="${fuzzer_name}_corpus"
59zip_name="$OUT/${fuzzer_name}_seed_corpus.zip"
60if [[ ! -d "$SRC/usbguard/src/Tests/Fuzzers/$corpus_dir" ]] ; then
61  rm -f "${zip_name}"
62  rm -rf "${corpus_dir}"
63  mkdir -p "${corpus_dir}"
64  pushd "${corpus_dir}"
65  i=1000000
66  while read -r line; do
67    echo "${line}" > "$((i++))"
68  done < <( cat $SRC/usbguard/src/Tests/Rules/test-rules.good \
69            $SRC/usbguard/src/Tests/Rules/test-rules.bad )
70  popd
71  zip -r "${zip_name}" "${corpus_dir}"
72fi
73
74# fuzzer-usb-descriptor seed corpus.
75fuzzer_name=fuzzer-usb-descriptor
76corpus_dir="${fuzzer_name}_corpus"
77zip_name="$OUT/${fuzzer_name}_seed_corpus.zip"
78if [[ ! -d "$SRC/usbguard/src/Tests/Fuzzers/$corpus_dir" ]] ; then
79  rm -rf "${corpus_dir}"
80  rm -f "${zip_name}"
81  cp -R "$SRC/usbguard/src/Tests/USB/data" "${corpus_dir}"
82  zip -r "${zip_name}" "${corpus_dir}"
83fi
84