ofz#44991 don't skip over terminator
[LibreOffice.git] / bin / oss-fuzz-build.sh
blob906cadd500d45b60be56c8cd1d9bbda2f10ea415
1 #!/usr/bin/env bash
3 set -e
5 if [ -z "${OUT}" ] || [ -z "${SRC}" ] || [ -z "${WORK}" ]; then
6 echo "OUT, SRC or WORK not set - script expects to be called inside oss-fuzz build env"
7 exit 1
8 fi
10 echo start at `date -u`
12 #shuffle CXXFLAGS -stdlib=libc++ arg into CXX as well because we use
13 #the CXX as the linker and need to pass -stdlib=libc++ to build
14 export CXX="$CXX -stdlib=libc++ -fsanitize-blacklist=$SRC/libreoffice/bin/sanitize-excludelist.txt"
15 export CC="$CC -fsanitize-blacklist=$SRC/libreoffice/bin/sanitize-excludelist.txt"
16 #similarly force the -fsanitize etc args in as well as pthread to get
17 #things to link successfully during the build
18 export LDFLAGS="$CFLAGS -Wl,--compress-debug-sections,zlib -lpthread"
20 df -h $OUT $WORK
22 cd $WORK
23 $SRC/libreoffice/autogen.sh --with-distro=LibreOfficeOssFuzz --with-external-tar=$SRC
25 make clean
27 #build-time rsc tool leaks a titch
28 export ASAN_OPTIONS="detect_leaks=0"
30 make fuzzers
32 pushd instdir/program
33 head -c -14 services.rdb > templateservices.rdb
34 tail -c +85 ./services/services.rdb >> templateservices.rdb
35 for a in *fuzzer; do
36 #some minimal fonts required
37 mv $a $OUT
38 mkdir -p $OUT/$a.fonts
39 tar -x -C $OUT/$a.fonts --strip-components=1 --wildcards --no-anchored '*.ttf' -f $SRC/liberation-fonts-ttf*
40 cp $SRC/*opens___.ttf $OUT/$a.fonts
41 #minimal runtime requirements
42 cp templateservices.rdb $OUT/$a.services.rdb
43 cp types.rdb $OUT/$a.types.rdb
44 cp types/offapi.rdb $OUT/$a.moretypes.rdb
45 cat > $OUT/$a.unorc << EOF
46 [Bootstrap]
47 URE_INTERNAL_LIB_DIR=\${ORIGIN}
48 UNO_TYPES=\${ORIGIN}/$a.types.rdb \${ORIGIN}/$a.moretypes.rdb
49 UNO_SERVICES=\${ORIGIN}/$a.services.rdb
50 EOF
51 done
52 popd
54 df -h $OUT $WORK
56 #starting corpuses
57 for zip_file in $SRC/*_seed_corpus.zip; do
58 cp $zip_file $OUT
59 done
60 #fuzzing dictionaries
61 cp $SRC/*.dict $OUT
62 #options files
63 cp $SRC/libreoffice/vcl/workben/*.options $OUT
65 echo end at `date -u`