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 48cd $SRC/cpython 49cp $SRC/python-library-fuzzers/python_coverage.h Python/ 50 51# Patch the interpreter to record code coverage 52sed -i '1 s/^.*$/#include "python_coverage.h"/g' Python/ceval.c 53sed -i 's/case TARGET\(.*\): {/\0\nfuzzer_record_code_coverage(f->f_code, f->f_lasti);/g' Python/ceval.c 54 55./configure "${FLAGS[@]:-}" --prefix=$CPYTHON_INSTALL_PATH 56make -j$(nproc) 57make install 58 59cp -R $CPYTHON_INSTALL_PATH $OUT/ 60 61cd $SRC/python-library-fuzzers 62make 63 64cp $SRC/python-library-fuzzers/fuzzer-html $OUT/ 65cp $SRC/python-library-fuzzers/html.py $OUT/ 66zip -j $OUT/fuzzer-html_seed_corpus.zip corp-html/* 67 68cp $SRC/python-library-fuzzers/fuzzer-email $OUT/ 69cp $SRC/python-library-fuzzers/email.py $OUT/ 70zip -j $OUT/fuzzer-email_seed_corpus.zip corp-email/* 71 72cp $SRC/python-library-fuzzers/fuzzer-httpclient $OUT/ 73cp $SRC/python-library-fuzzers/httpclient.py $OUT/ 74zip -j $OUT/fuzzer-httpclient_seed_corpus.zip corp-httpclient/* 75 76cp $SRC/python-library-fuzzers/fuzzer-json $OUT/ 77cp $SRC/python-library-fuzzers/json.py $OUT/ 78zip -j $OUT/fuzzer-json_seed_corpus.zip corp-json/* 79 80cp $SRC/python-library-fuzzers/fuzzer-difflib $OUT/ 81cp $SRC/python-library-fuzzers/difflib.py $OUT/ 82zip -j $OUT/fuzzer-difflib_seed_corpus.zip corp-difflib/* 83 84cp $SRC/python-library-fuzzers/fuzzer-csv $OUT/ 85cp $SRC/python-library-fuzzers/csv.py $OUT/ 86zip -j $OUT/fuzzer-csv_seed_corpus.zip corp-csv/* 87 88cp $SRC/python-library-fuzzers/fuzzer-decode $OUT/ 89cp $SRC/python-library-fuzzers/decode.py $OUT/ 90zip -j $OUT/fuzzer-decode_seed_corpus.zip corp-decode/* 91cp $SRC/python-library-fuzzers/fuzzer-decode.dict $OUT/ 92