1# Copyright 2020 Google Inc. 2# 3# Licensed under the Apache License, Version 2.0 (the "License"); 4# you may not use this file except in compliance with the License. 5# You may obtain a copy of the License at 6# 7# http://www.apache.org/licenses/LICENSE-2.0 8# 9# Unless required by applicable law or agreed to in writing, software 10# distributed under the License is distributed on an "AS IS" BASIS, 11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12# See the License for the specific language governing permissions and 13# limitations under the License. 14# 15################################################################################ 16 17#!/bin/bash 18 19# build libpng using the upstream-provided build.sh. 20# it will also build the vanilla (non-proto) fuzz target, 21# but we discard it. 22(cd libpng/ && contrib/oss-fuzz/build.sh && rm -rf $OUT/*) 23 24# Compile png_fuzz_proto.proto; should produce two files in genfiles/: 25# png_fuzz_proto.pb.cc png_fuzz_proto.pb.h 26rm -rf genfiles && mkdir genfiles && LPM/external.protobuf/bin/protoc png_fuzz_proto.proto --cpp_out=genfiles 27 28# compile the upstream-provided vanilla fuzz target 29# but replace LLVMFuzzerTestOneInput with FuzzPNG so that 30# png_proto_fuzzer_example.cc can call FuzzPNG from its own 31# LLVMFuzzerTestOneInput. 32$CXX $CXXFLAGS -c -DLLVMFuzzerTestOneInput=FuzzPNG libpng/contrib/oss-fuzz/libpng_read_fuzzer.cc -I libpng 33 34# compile & link the rest 35$CXX $CXXFLAGS png_proto_fuzzer_example.cc libpng_read_fuzzer.o genfiles/png_fuzz_proto.pb.cc \ 36 -I genfiles -I. -I libprotobuf-mutator/ -I LPM/external.protobuf/include \ 37 -lz \ 38 LPM/src/libfuzzer/libprotobuf-mutator-libfuzzer.a \ 39 LPM/src/libprotobuf-mutator.a \ 40 LPM/external.protobuf/lib/libprotobuf.a \ 41 libpng/.libs/libpng16.a \ 42 $LIB_FUZZING_ENGINE \ 43 -o $OUT/png_proto_fuzzer_example 44 45# custom png proto mutator 46$CXX $CXXFLAGS png_proto_fuzzer_example.cc png_proto_mutator.cc libpng_read_fuzzer.o genfiles/png_fuzz_proto.pb.cc \ 47 -I genfiles -I. -I libprotobuf-mutator/ -I LPM/external.protobuf/include \ 48 -lz \ 49 LPM/src/libfuzzer/libprotobuf-mutator-libfuzzer.a \ 50 LPM/src/libprotobuf-mutator.a \ 51 LPM/external.protobuf/lib/libprotobuf.a \ 52 libpng/.libs/libpng16.a \ 53 $LIB_FUZZING_ENGINE \ 54 -o $OUT/png_proto_fuzzer_example_custom_mutator 55 56echo > dummy.cc 57 58# A target, w/o protos but with a specialized custom mutator. 59$CXX $CXXFLAGS -c libpng/contrib/oss-fuzz/libpng_read_fuzzer.cc -I libpng 60$CXX $CXXFLAGS dummy.cc \ 61 -include fuzzer-test-suite/libpng-1.2.56/png_mutator.h \ 62 -D PNG_MUTATOR_DEFINE_LIBFUZZER_CUSTOM_MUTATOR \ 63 libpng_read_fuzzer.o \ 64 -lz \ 65 libpng/.libs/libpng16.a \ 66 $LIB_FUZZING_ENGINE \ 67 -o $OUT/png_custom_mutator_fuzzer_example 68 69# An experimental out-of-tree target, with a specialized custom mutator. 70$CXX $CXXFLAGS libpng_transforms_fuzzer.cc \ 71 -include fuzzer-test-suite/libpng-1.2.56/png_mutator.h \ 72 -D PNG_MUTATOR_DEFINE_LIBFUZZER_CUSTOM_MUTATOR \ 73 -I libpng \ 74 -lz \ 75 libpng/.libs/libpng16.a \ 76 $LIB_FUZZING_ENGINE \ 77 -o $OUT/png_transforms_fuzzer 78