• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/bin/bash -eu
2# Copyright 2019 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#
16################################################################################
17
18# Ignore memory leaks from python scripts invoked in the build
19export ASAN_OPTIONS="detect_leaks=0"
20export MSAN_OPTIONS="halt_on_error=0:exitcode=0:report_umrs=0"
21
22# Remove -pthread from CFLAGS, this trips up ./configure
23# which thinks pthreads are available without any CLI flags
24CFLAGS=${CFLAGS//"-pthread"/}
25
26FLAGS=()
27case $SANITIZER in
28  address)
29    FLAGS+=("--with-address-sanitizer")
30    ;;
31  memory)
32    FLAGS+=("--with-memory-sanitizer")
33    # installing ensurepip takes a while with MSAN instrumentation, so
34    # we disable it here
35    FLAGS+=("--without-ensurepip")
36    # -msan-keep-going is needed to allow MSAN's halt_on_error to function
37    FLAGS+=("CFLAGS=-mllvm -msan-keep-going=1")
38    ;;
39  undefined)
40    FLAGS+=("--with-undefined-behavior-sanitizer")
41    ;;
42esac
43
44export CPYTHON_INSTALL_PATH=$SRC/cpython-install
45rm -rf $CPYTHON_INSTALL_PATH
46mkdir $CPYTHON_INSTALL_PATH
47
48tar zxf v3.8.7.tar.gz
49cd cpython-3.8.7/
50cp $SRC/django-fuzzers/python_coverage.h Python/
51
52# Patch the interpreter to record code coverage
53sed -i '1 s/^.*$/#include "python_coverage.h"/g' Python/ceval.c
54sed -i 's/case TARGET\(.*\): {/\0\nfuzzer_record_code_coverage(f->f_code, f->f_lasti);/g' Python/ceval.c
55
56./configure "${FLAGS[@]:-}" --prefix=$CPYTHON_INSTALL_PATH
57make -j$(nproc)
58make install
59
60cp -R $CPYTHON_INSTALL_PATH $OUT/
61
62rm -rf $OUT/django-dependencies
63mkdir $OUT/django-dependencies
64$CPYTHON_INSTALL_PATH/bin/pip3 install asgiref pytz sqlparse -t $OUT/django-dependencies
65
66cd $SRC/django-fuzzers
67rm $CPYTHON_INSTALL_PATH/lib/python3.8/lib-dynload/_tkinter*.so
68make
69
70cp -R $SRC/django/* $OUT/
71
72cp $SRC/django-fuzzers/fuzzer-utils $OUT/
73cp $SRC/django-fuzzers/utils.py $OUT/
74zip -j $OUT/fuzzer-utils_seed_corpus.zip $SRC/django-fuzzers/corp-utils/*
75