1#!/bin/bash -eu 2# Copyright 2020 Google Inc. 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# 16export ORIG_CFLAGS=${CFLAGS} 17cd haproxy 18 19# Fix some things in the Makefile where there are no options available 20sed 's/CFLAGS = $(ARCH_FLAGS) $(CPU_CFLAGS) $(DEBUG_CFLAGS) $(SPEC_CFLAGS)/CFLAGS = $(ARCH_FLAGS) $(CPU_CFLAGS) $(DEBUG_CFLAGS) $(SPEC_CFLAGS) ${ORIG_CFLAGS}/g' -i Makefile 21sed 's/LDFLAGS = $(ARCH_FLAGS) -g/LDFLAGS = $(ARCH_FLAGS) -g ${CXXFLAGS}/g' -i Makefile 22make TARGET=generic CC=${CC} LD=${CXX} 23 24# Make a copy of the main file since it has many global functions we need to declare 25# We dont want the main function but we need the rest of the stuff in haproxy.c 26cd /src/haproxy 27sed 's/int main(int argc/int main2(int argc/g' -i ./src/haproxy.c 28sed 's/dladdr(main,/dladdr(main2,/g' -i ./src/tools.c 29sed 's/(void*)main/(void*)main2/g' -i ./src/tools.c 30 31 32SETTINGS="-Iinclude -g -DUSE_POLL -DUSE_TPROXY -DCONFIG_HAPROXY_VERSION=\"\" -DCONFIG_HAPROXY_DATE=\"\"" 33 34$CC $CFLAGS $SETTINGS -c -o ./src/haproxy.o ./src/haproxy.c 35ar cr libhaproxy.a ./src/*.o 36 37for fuzzer in hpack_decode cfg_parser; do 38 cp $SRC/fuzz_${fuzzer}.c . 39 $CC $CFLAGS $SETTINGS -c fuzz_${fuzzer}.c -o fuzz_${fuzzer}.o 40 $CXX -g $CXXFLAGS $LIB_FUZZING_ENGINE fuzz_${fuzzer}.o libhaproxy.a -o $OUT/fuzz_${fuzzer} 41done 42