• 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
18export ASAN_OPTIONS="detect_leaks=0"
19
20git apply  --ignore-space-change --ignore-whitespace $SRC/fuzz_patch.patch
21
22export OSS_CFLAGS="$CFLAGS -g"
23
24sed -i 's/CFLAGS        =/CFLAGS        = ${OSS_CFLAGS} /g' ./Makefile
25sed -i 's/LDFLAGS       =/LDFLAGS       = ${OSS_CFLAGS} /g' ./Makefile
26
27# Do some modificatiosn to the source
28sed -i 's/recvmsg(/fuzz_recvmsg(/g' ./src/dhcp-common.c
29sed -i 's/recvmsg(/fuzz_recvmsg(/g' ./src/netlink.c
30sed -i 's/ioctl(/fuzz_ioctl(/g' ./src/dhcp.c
31sed -i 's/ioctl(/fuzz_ioctl(/g' ./src/network.c
32
33sed -i 's/if (errno != 0/if (errno == 123123/g' ./src/netlink.c
34
35echo "" >> ./src/dnsmasq.c
36echo "ssize_t fuzz_recvmsg(int sockfd, struct msghdr *msg, int flags) {return -1;}" >> ./src/dnsmasq.c
37echo "int fuzz_ioctl(int fd, unsigned long request, void *arg) {return -1;}" >> ./src/dnsmasq.c
38make
39
40# Remove main function and create an archive
41cd ./src
42sed -i 's/int main (/int main2 (/g' ./dnsmasq.c
43sed -i 's/fuzz_recvmsg(/fuzz_recvmsg2(/g' ./dnsmasq.c
44sed -i 's/fuzz_ioctl(/fuzz_ioctl2(/g' ./dnsmasq.c
45
46rm dnsmasq.o
47$CC $CFLAGS -c dnsmasq.c -o dnsmasq.o -I./ -DVERSION=\'\"UNKNOWN\"\'
48ar cr libdnsmasq.a *.o
49
50sed -i 's/class/class2/g' ./dnsmasq.h
51sed -i 's/new/new2/g' ./dnsmasq.h
52
53# Build the fuzzers
54for fuzz_name in dhcp6 rfc1035 auth dhcp util; do
55    $CC $CFLAGS -c $SRC/fuzz_${fuzz_name}.c -I./ -I$SRC/ -DVERSION=\'\"UNKNOWN\"\' -g
56    $CC $CFLAGS $LIB_FUZZING_ENGINE ./fuzz_${fuzz_name}.o libdnsmasq.a -o $OUT/fuzz_${fuzz_name}
57done
58