1#!/bin/bash -eu 2# Copyright 2018 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 18pushd $SRC/Python-2.7.15/ 19patch -p1 <<'EOF' 20Index: v2_7_unstable/Python/pymath.c 21=================================================================== 22--- v2_7_unstable.orig/Python/pymath.c 23+++ v2_7_unstable/Python/pymath.c 24@@ -18,6 +18,7 @@ double _Py_force_double(double x) 25 /* inline assembly for getting and setting the 387 FPU control word on 26 gcc/x86 */ 27 28+__attribute__((no_sanitize_memory)) 29 unsigned short _Py_get_387controlword(void) { 30 unsigned short cw; 31 __asm__ __volatile__ ("fnstcw %0" : "=m" (cw)); 32Index: v2_7_unstable/Modules/_ctypes/callproc.c 33=================================================================== 34--- v2_7_unstable.orig/Modules/_ctypes/callproc.c 35+++ v2_7_unstable/Modules/_ctypes/callproc.c 36@@ -1166,6 +1166,10 @@ PyObject *_ctypes_callproc(PPROC pProc, 37 38 rtype = _ctypes_get_ffi_type(restype); 39 resbuf = alloca(max(rtype->size, sizeof(ffi_arg))); 40+ /* ffi_call actually initializes resbuf, but from asm, which 41+ * MemorySanitizer can't detect. Avoid false positives from MSan. */ 42+ if (resbuf != NULL) 43+ memset(resbuf, 0, max(rtype->size, sizeof(ffi_arg))); 44 45 avalues = (void **)alloca(sizeof(void *) * argcount); 46 atypes = (ffi_type **)alloca(sizeof(ffi_type *) * argcount); 47EOF 48 49if [ -e $OUT/sanpy/cflags -a "$(cat $OUT/sanpy/cflags)" = "${CFLAGS}" ] ; then 50 echo 'Python cflags unchanged, no need to rebuild' 51else 52 rm -rf $OUT/sanpy 53 ASAN_OPTIONS=detect_leaks=0 ./configure --without-pymalloc \ 54 --prefix=$OUT/sanpy CFLAGS="${CFLAGS}" LINKCC="${CXX}" \ 55 LDFLAGS="${CXXFLAGS}" 56 grep -v HAVE_GETC_UNLOCKED < pyconfig.h > tmp && mv tmp pyconfig.h 57 ASAN_OPTIONS=detect_leaks=0 make && make install 58 echo "${CFLAGS}" > $OUT/sanpy/cflags 59fi 60popd 61 62cd contrib/fuzz 63make clean oss-fuzz 64