• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/bin/bash -eu
2# Copyright 2020 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# Workaround for fixing AFL++ build, discarded for others.
19# See https://github.com/google/oss-fuzz/issues/4280#issuecomment-773977943
20export AFL_LLVM_INSTRUMENT=CLASSIC,NGRAM-4
21
22# Compile NSS
23mkdir $SRC/nss-nspr
24mv $SRC/nss $SRC/nss-nspr/
25mv $SRC/nspr $SRC/nss-nspr/
26cd $SRC/nss-nspr/
27# We do not need NSS to be built with address sanitizer
28CFLAGS="" CXXFLAGS="" nss/build.sh --static
29
30# Create a package config for NSS
31cp dist/Debug/lib/pkgconfig/{nspr,nss}.pc
32sed -i "s/Debug//g" dist/Debug/lib/pkgconfig/nss.pc
33sed -i "s/\/lib/\/lib\/Debug/g" dist/Debug/lib/pkgconfig/nss.pc
34sed -i "s/include\/nspr/public\/nss/g" dist/Debug/lib/pkgconfig/nss.pc
35sed -i "s/NSPR/NSS/g" dist/Debug/lib/pkgconfig/nss.pc
36LIBS="-lssl -lsmime -lnssdev -lnss_static -lpk11wrap_static -lcryptohi"
37LIBS="$LIBS -lcerthi -lcertdb -lnssb -lnssutil -lnsspki -ldl -lm -lsqlite"
38LIBS="$LIBS -lsoftokn_static -lsha-x86_c_lib -lfreebl_static"
39LIBS="$LIBS -lgcm-aes-x86_c_lib -lhw-acc-crypto-avx -lhw-acc-crypto-avx2"
40sed -i "s/Libs:.*/Libs: -L\${libdir} $LIBS/g" dist/Debug/lib/pkgconfig/nss.pc
41echo "Requires: nspr" >> dist/Debug/lib/pkgconfig/nss.pc
42
43export NSS_NSPR_PATH=$(realpath $SRC/nss-nspr/)
44export PKG_CONFIG_PATH=$NSS_NSPR_PATH/dist/Debug/lib/pkgconfig
45export LD_LIBRARY_PATH=$NSS_NSPR_PATH/dist/Debug/lib
46
47# compile libcacard
48BUILD=$WORK/meson
49rm -rf $BUILD
50mkdir $BUILD
51
52cd $SRC/libcacard
53# Drop the tests as they are not needed and require too much dependencies
54meson $BUILD -Ddefault_library=static -Ddisable_tests=true
55ninja -C $BUILD
56
57# We need nss db to work
58cp -r tests/db $OUT/
59
60echo "XXXXXXXX" > $WORK/testinput
61
62fuzzers=$(find $BUILD/fuzz/ -executable -type f)
63for f in $fuzzers; do
64	fuzzer=$(basename $f)
65	cp $f $OUT/
66	# Check if it runs at least in build image
67	$OUT/$fuzzer $WORK/testinput
68	#zip -j $OUT/${fuzzer}_seed_corpus.zip fuzz/corpora/${fuzzer}/*
69done
70
71rm $WORK/testinput
72