aboutsummaryrefslogtreecommitdiff
path: root/projects/dnsmasq/build.sh
blob: 8fc7b21d98667965c61bfcd9bf25beb8409b721c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#!/bin/bash -eu
# Copyright 2021 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
################################################################################

export ASAN_OPTIONS="detect_leaks=0"

git apply  --ignore-space-change --ignore-whitespace $SRC/fuzz_patch.patch 

export OSS_CFLAGS="$CFLAGS -g"

sed -i 's/CFLAGS        =/CFLAGS        = ${OSS_CFLAGS} /g' ./Makefile
sed -i 's/LDFLAGS       =/LDFLAGS       = ${OSS_CFLAGS} /g' ./Makefile

# Do some modificatiosn to the source
sed -i 's/recvmsg(/fuzz_recvmsg(/g' ./src/dhcp-common.c 
sed -i 's/recvmsg(/fuzz_recvmsg(/g' ./src/netlink.c 
sed -i 's/ioctl(/fuzz_ioctl(/g' ./src/dhcp.c
sed -i 's/ioctl(/fuzz_ioctl(/g' ./src/network.c

sed -i 's/if (errno != 0/if (errno == 123123/g' ./src/netlink.c

echo "" >> ./src/dnsmasq.c 
echo "ssize_t fuzz_recvmsg(int sockfd, struct msghdr *msg, int flags) {return -1;}" >> ./src/dnsmasq.c
echo "int fuzz_ioctl(int fd, unsigned long request, void *arg) {return -1;}" >> ./src/dnsmasq.c
make

# Remove main function and create an archive
cd ./src
sed -i 's/int main (/int main2 (/g' ./dnsmasq.c
sed -i 's/fuzz_recvmsg(/fuzz_recvmsg2(/g' ./dnsmasq.c
sed -i 's/fuzz_ioctl(/fuzz_ioctl2(/g' ./dnsmasq.c

rm dnsmasq.o
$CC $CFLAGS -c dnsmasq.c -o dnsmasq.o -I./ -DVERSION=\'\"UNKNOWN\"\' 
ar cr libdnsmasq.a *.o

sed -i 's/class/class2/g' ./dnsmasq.h
sed -i 's/new/new2/g' ./dnsmasq.h

# Build the fuzzers
for fuzz_name in dhcp6 rfc1035 auth dhcp util; do
    $CC $CFLAGS -c $SRC/fuzz_${fuzz_name}.c -I./ -I$SRC/ -DVERSION=\'\"UNKNOWN\"\' -g
    $CC $CFLAGS $LIB_FUZZING_ENGINE ./fuzz_${fuzz_name}.o libdnsmasq.a -o $OUT/fuzz_${fuzz_name}
done