• 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# Place to keep dependencies for static linking
19DEPS=/deps
20mkdir ${DEPS}
21
22
23# Build libffi
24cd $SRC
25tar xvfz libffi-3.2.1.tar.gz
26cd libffi-3.2.1
27./configure --disable-shared
28make -j$(nproc)
29export LIBFFI_LIBS="-L/src/libffi-3.2.1 libraries/ -lffi"
30cp ./x86_64-unknown-linux-gnu/.libs/libffi.a ${DEPS}/
31
32
33# Build libxml2
34cd $SRC/libxml2
35./autogen.sh \
36    --disable-shared \
37    --without-debug \
38    --without-ftp \
39    --without-http \
40    --without-legacy \
41    --without-python
42make -j$(nproc)
43make install
44cp .libs/libxml2.a ${DEPS}/
45
46
47# Build glib
48cd $SRC/glib
49GLIB_BUILD=$WORK/meson
50rm -rf $GLIB_BUILD
51mkdir $GLIB_BUILD
52meson $GLIB_BUILD \
53  -Db_lundef=false \
54  -Ddefault_library=static \
55  -Dlibmount=disabled
56ninja -C $GLIB_BUILD
57ninja -C $GLIB_BUILD install
58
59cp ${GLIB_BUILD}/gobject/libgobject-2.0.a ${DEPS}/
60cp ${GLIB_BUILD}/gmodule/libgmodule-2.0.a ${DEPS}/
61cp ${GLIB_BUILD}/glib/libglib-2.0.a ${DEPS}/
62
63
64# Build Pidgin
65cd $SRC
66tar -xf pidgin-2.14.5.tar.bz2
67mv pidgin-2.14.5 pidgin
68cd pidgin
69./configure --disable-consoleui \
70            --disable-shared \
71            --disable-screensaver \
72            --disable-sm \
73            --disable-gtkspell \
74            --disable-gevolution \
75            --enable-gnutls=no \
76            --disable-gstreamer \
77            --disable-vv \
78            --disable-idn \
79            --disable-meanwhile \
80            --disable-avahi \
81            --disable-dbus \
82            --disable-perl \
83            --disable-tcl \
84            --disable-cyrus-sasl \
85            --disable-gtkui \
86            --enable-nss=no
87make -j$(nproc)
88
89
90# Build fuzzers
91readonly FUZZERS=( \
92  pidgin_xml_fuzzer
93  pidgin_utils_fuzzer
94)
95
96cd libpurple
97cp $SRC/*fuzzer.c .
98
99for fuzzer in "${FUZZERS[@]}"; do
100  $CC $CFLAGS -DHAVE_CONFIG_H \
101    -I. \
102    -I.. \
103    -I${SRC}/glib \
104    -I${SRC}/glib/glib \
105    -I${SRC}/glib/gmodule \
106    -I${GLIB_BUILD} \
107    -I${GLIB_BUILD}/glib \
108    -I/usr/lib/x86_64-linux-gnu/glib-2.0/include \
109    -I/src/pidgin/libpurple/protocols/jabber \
110    -I/usr/local/include/libxml2 \
111    -c $fuzzer.c \
112    -o $fuzzer.o
113
114  $CC $CXXFLAGS $LIB_FUZZING_ENGINE $fuzzer.o \
115    -o $OUT/$fuzzer \
116    /src/pidgin/libpurple/protocols/jabber/.libs/libjabber.a \
117    ./.libs/libpurple.a \
118    ${DEPS}/libxml2.a \
119    ${DEPS}/libgobject-2.0.a \
120    ${DEPS}/libgmodule-2.0.a \
121    ${DEPS}/libglib-2.0.a \
122    ${DEPS}/libffi.a \
123    -lresolv -lz -llzma
124done
125
126zip $OUT/pidgin_xml_fuzzer_seed_corpus.zip $SRC/go-fuzz-corpus/xml/corpus/*
127cp $SRC/fuzzing/dictionaries/xml.dict $OUT/pidgin_xml_fuzzer.dict
128