• 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# Instrument mruby
19(
20cd $SRC/mruby
21export LD=$CC
22export LDFLAGS="$CFLAGS"
23rake -m
24
25# build fuzzers
26FUZZ_TARGET=$SRC/mruby/oss-fuzz/mruby_fuzzer.c
27name=$(basename $FUZZ_TARGET .c)
28$CC -c $CFLAGS -Iinclude \
29     ${FUZZ_TARGET} -o $OUT/${name}.o
30$CXX $CXXFLAGS $OUT/${name}.o $LIB_FUZZING_ENGINE -lm \
31    $SRC/mruby/build/host/lib/libmruby.a -o $OUT/${name}
32rm -f $OUT/${name}.o
33)
34
35# Build proto fuzzer: ASan and UBSan
36if [[ $CFLAGS != *sanitize=memory* ]]; then
37    PROTO_FUZZ_TARGET=$SRC/mruby/oss-fuzz/mruby_proto_fuzzer.cpp
38    PROTO_CONVERTER=$SRC/mruby/oss-fuzz/proto_to_ruby.cpp
39    rm -rf $SRC/mruby/genfiles
40    mkdir $SRC/mruby/genfiles
41    $SRC/LPM/external.protobuf/bin/protoc --proto_path=$SRC/mruby/oss-fuzz ruby.proto --cpp_out=$SRC/mruby/genfiles
42    $CXX -c $CXXFLAGS $SRC/mruby/genfiles/ruby.pb.cc -o $SRC/mruby/genfiles/ruby.pb.o -I $SRC/LPM/external.protobuf/include
43    $CXX -I $SRC/mruby/include -I $SRC/LPM/external.protobuf/include $CXXFLAGS $PROTO_FUZZ_TARGET $SRC/mruby/genfiles/ruby.pb.o $PROTO_CONVERTER \
44      -I $SRC/mruby/genfiles \
45      -I $SRC/libprotobuf-mutator \
46      -I $SRC/mruby/include -lz -lm \
47      $SRC/LPM/src/libfuzzer/libprotobuf-mutator-libfuzzer.a \
48      $SRC/LPM/src/libprotobuf-mutator.a \
49      $SRC/LPM/external.protobuf/lib/libprotobuf.a \
50      $SRC/mruby/build/host/lib/libmruby.a \
51      $LIB_FUZZING_ENGINE \
52      -o $OUT/mruby_proto_fuzzer
53
54    # Copy config
55    cp $SRC/mruby/oss-fuzz/config/mruby_proto_fuzzer.options $OUT
56fi
57
58# dict and config
59cp $SRC/mruby/oss-fuzz/config/mruby.dict $OUT
60cp $SRC/mruby/oss-fuzz/config/mruby_fuzzer.options $OUT
61
62# seeds
63zip -rq $OUT/mruby_fuzzer_seed_corpus $SRC/mruby_seeds
64