• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/bin/bash -eu
2# Copyright (C) 2018 Cisco Systems, Inc. and/or its affiliates. All rights reserved.
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
18set -ex
19export GIT_DISCOVERY_ACROSS_FILESYSTEM=1
20
21#
22# Build the library.
23#
24rm -rf ${WORK}/build
25mkdir -p ${WORK}/build
26cd ${WORK}/build
27
28#
29# Run ./configure
30#
31export CLAMAV_DEPENDENCIES=/mussels/install
32cmake ${SRC}/clamav-devel \
33    -DENABLE_FUZZ=ON                                                   \
34    -DHAVE_MMAP=OFF                                                    \
35    -DJSONC_INCLUDE_DIR="$CLAMAV_DEPENDENCIES/include/json-c"          \
36    -DJSONC_LIBRARY="$CLAMAV_DEPENDENCIES/lib/libjson-c.a"             \
37    -DENABLE_JSON_SHARED=OFF                                           \
38    -DBZIP2_INCLUDE_DIR="$CLAMAV_DEPENDENCIES/include"                 \
39    -DBZIP2_LIBRARY_RELEASE="$CLAMAV_DEPENDENCIES/lib/libbz2_static.a" \
40    -DOPENSSL_ROOT_DIR="$CLAMAV_DEPENDENCIES"                          \
41    -DOPENSSL_INCLUDE_DIR="$CLAMAV_DEPENDENCIES/include"               \
42    -DOPENSSL_CRYPTO_LIBRARY="$CLAMAV_DEPENDENCIES/lib/libcrypto.a"    \
43    -DOPENSSL_SSL_LIBRARY="$CLAMAV_DEPENDENCIES/lib/libssl.a"          \
44    -DZLIB_LIBRARY="$CLAMAV_DEPENDENCIES/lib/libssl.a"                 \
45    -DLIBXML2_INCLUDE_DIR="$CLAMAV_DEPENDENCIES/include/libxml2"       \
46    -DLIBXML2_LIBRARY="$CLAMAV_DEPENDENCIES/lib/libxml2.a"             \
47    -DPCRE2_INCLUDE_DIR="$CLAMAV_DEPENDENCIES/include"                 \
48    -DPCRE2_LIBRARY="$CLAMAV_DEPENDENCIES/lib/libpcre2-8.a"            \
49    -DZLIB_INCLUDE_DIR="$CLAMAV_DEPENDENCIES/include"                  \
50    -DZLIB_LIBRARY="$CLAMAV_DEPENDENCIES/lib/libz.a"                   \
51    -DCMAKE_INSTALL_PREFIX="install"
52
53# Build libclamav and the fuzz targets
54make -j4
55cp ./fuzz/clamav_* ${OUT}/.
56
57#
58# Collect the fuzz corpora.
59#
60
61# `scanfile` & `scanmap`
62# ----------
63mkdir ${WORK}/all-scantype-seeds
64
65for type in ARCHIVE MAIL OLE2 PDF HTML PE ELF SWF XMLDOCS HWP3; do
66    # Prepare seed corpus for the type-specific fuzz targets.
67    zip ${OUT}/clamav_scanfile_${type}_fuzzer_seed_corpus.zip ${SRC}/clamav-fuzz-corpus/scantype/${type}/*
68    zip ${OUT}/clamav_scanmap_${type}_fuzzer_seed_corpus.zip ${SRC}/clamav-fuzz-corpus/scantype/${type}/*
69
70    # Prepare dictionary for the type-specific fuzz targets (may not exist for all types).
71    cp ${SRC}/clamav-fuzz-corpus/scantype/${type}.dict ${OUT}/clamav_scanfile_${type}_fuzzer.dict 2>/dev/null || :
72    cp ${SRC}/clamav-fuzz-corpus/scantype/${type}.dict ${OUT}/clamav_scanmap_${type}_fuzzer.dict 2>/dev/null || :
73
74    # Copy seeds for the generic fuzz target.
75    cp ${SRC}/clamav-fuzz-corpus/scantype/${type}/* ${WORK}/all-scantype-seeds/
76done
77
78# Prepare seed corpus for the generic fuzz target.
79cp ${SRC}/clamav-fuzz-corpus/scantype/other/* ${WORK}/all-scantype-seeds/
80zip ${OUT}/clamav_scanfile_fuzzer_seed_corpus.zip ${WORK}/all-scantype-seeds/*
81zip ${OUT}/clamav_scanmap_fuzzer_seed_corpus.zip ${WORK}/all-scantype-seeds/*
82rm -r ${WORK}/all-scantype-seeds
83
84# `dbload`
85# --------
86for type in CDB CFG CRB FP FTM HDB HSB IDB IGN IGN2 LDB MDB MSB NDB PDB WDB YARA; do
87    # Prepare seed corpus for the type-specific fuzz targets.
88    zip ${OUT}/clamav_dbload_${type}_fuzzer_seed_corpus.zip ${SRC}/clamav-fuzz-corpus/database/${type}/*
89
90    # Prepare dictionary for the type-specific fuzz targets (may not exist for all types).
91    cp ${SRC}/clamav-fuzz-corpus/database/${type}.dict ${OUT}/clamav_dbload_${type}_fuzzer.dict 2>/dev/null || :
92done
93