1#!/bin/bash -eu
2# Copyright 2019 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
18cd 'tests'
19
20export LDO=$CXX
21export LDFLAGS="$CXXFLAGS $LIB_FUZZING_ENGINE"
22export CFLAGS="$CFLAGS -MMD"
23
24if [[ "$ARCHITECTURE" == "i386" ]]; then
25	# Force static link
26	rm -v /lib/i386-linux-gnu/libcrypto.so* || :
27fi
28
29# Specific to hostap's rules.include: set empty, as we directly set required
30# sanitizer flags in CFLAGS and LDFLAGS (above).
31export FUZZ_FLAGS=
32
33for target in fuzzing/*; do
34  [[ -d "$target" ]] || continue
35
36  if [[ "$SANITIZER" == "dataflow" ]]; then
37	  # libcrypto seems to cause problems with 'dataflow' sanitizer.
38	  [[ "$target" == "fuzzing/dpp-uri" ]] && continue || :
39	  [[ "$target" == "fuzzing/sae" ]] && continue || :
40  fi
41
42  (
43    cd "$target"
44    make clean
45
46    if [[ "$target" == "fuzzing/tls-server" ]]; then
47      export CFLAGS="$CFLAGS -DCERTDIR='\"hwsim/auth_serv/\"'"
48    fi
49
50    make -j$(nproc) V=1 LIBFUZZER=y
51    mv -v "${target##*/}" "${OUT}/"
52
53    if [[ -d 'corpus' ]]; then
54      (cd 'corpus' && zip "${OUT}/${target##*/}_seed_corpus.zip" *)
55    fi
56  )
57done
58
59# Copy required data.
60cp -a "hwsim" "${OUT}/"
61