• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/bin/bash -eu
2# Copyright 2021 Google LLC
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
19function copy_lib
20    {
21    local fuzzer_path=$1
22    local lib=$2
23    cp $(ldd ${fuzzer_path} | grep "${lib}" | awk '{ print $3 }') ${OUT}/lib/ || true
24    }
25
26mkdir -p $OUT/lib
27
28# build dependency
29(
30cd $SRC/libyang
31mkdir build; cd build
32cmake -DBUILD_SHARED_LIBS=OFF -DENABLE_LYD_PRIV=ON -DCMAKE_INSTALL_PREFIX:PATH=/usr \
33    -D CMAKE_BUILD_TYPE:String="Release" ..
34make -j$(nproc)
35make install
36)
37
38# build project
39export ASAN_OPTIONS=detect_leaks=0
40./bootstrap.sh
41./configure --enable-libfuzzer --enable-static --enable-static-bin --sbindir=$SRC/bin
42make -j$(nproc)
43make install
44cp ./lib/.libs/libfrr.so.0 $OUT/lib/
45cp $SRC/bin/bgpd $OUT/
46cp $SRC/bin/ospfd $OUT/
47cp $SRC/bin/pimd $OUT/
48cp $SRC/bin/zebra $OUT/
49
50# build corpus
51cd $SRC/corpi
52find . -type d -maxdepth 1 | while read i; do zip -j $OUT/"$i"_seed_corpus.zip "$i"/*; done
53
54find $OUT -maxdepth 1 -type f -executable | while read i; do
55    grep "LLVMFuzzerTestOneInput" ${i} > /dev/null 2>&1 || continue
56    patchelf --set-rpath '$ORIGIN/lib' ${i}
57    copy_lib ${i} libpcre2
58    copy_lib ${i} libyang
59    copy_lib ${i} libelf
60    copy_lib ${i} libjson-c
61done
62
63patchelf --remove-needed libpcre2-8.so.0 $OUT/lib/libyang.so.2
64