aboutsummaryrefslogtreecommitdiffhomepage
path: root/projects/grpc/build.sh
blob: 51be391e86954fc581340bd85316ff0e720ccbf9 (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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#!/bin/bash -eu
# Copyright 2016 Google Inc.
#
# 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.
#
################################################################################

FUZZER_FILES="\
test/core/json/fuzzer.cc \
test/core/client_channel/uri_fuzzer_test.cc \
test/core/http/request_fuzzer.cc \
test/core/http/response_fuzzer.cc \
test/core/nanopb/fuzzer_response.cc \
test/core/nanopb/fuzzer_serverlist.cc \
test/core/slice/percent_decode_fuzzer.cc \
test/core/slice/percent_encode_fuzzer.cc \
test/core/transport/chttp2/hpack_parser_fuzzer_test.cc \
test/core/end2end/fuzzers/api_fuzzer.cc \
test/core/end2end/fuzzers/client_fuzzer.cc \
test/core/end2end/fuzzers/server_fuzzer.cc \
test/core/security/ssl_server_fuzzer.cc \
"

FUZZER_DICTIONARIES="\
test/core/end2end/fuzzers/api_fuzzer.dictionary \
test/core/end2end/fuzzers/hpack.dictionary \
"

FUZZER_LIBRARIES="\
bazel-bin/*.a \
bazel-bin/test/core/util/*.a \
bazel-bin/test/core/end2end/*.a \
bazel-bin/external/boringssl/libssl.a \
bazel-bin/external/boringssl/libcrypto.a \
bazel-bin/external/submodule_cares/*.a \
bazel-bin/external/submodule_zlib/*.a \
bazel-bin/third_party/nanopb/*.a \
bazel-bin/*.a \
"

# build grpc
# Temporary hack, see https://github.com/google/oss-fuzz/issues/383
NO_VPTR="--copt=-fno-sanitize=vptr --linkopt=-fno-sanitize=vptr"
EXTERA_BAZEL_FLAGS="--strip=never  $(for f in $CXXFLAGS; do if [ $f != "-stdlib=libc++" ] ; then echo --copt=$f --linkopt=$f; fi; done)"
bazel build --dynamic_mode=off --spawn_strategy=standalone --genrule_strategy=standalone \
  $EXTERA_BAZEL_FLAGS \
  $NO_VPTR \
  :all test/core/util/... test/core/end2end/... third_party/nanopb/... @boringssl//:all @submodule_zlib//:all @submodule_cares//:all

CFLAGS="${CFLAGS} -Iinclude -I."
CXXFLAGS="${CXXFLAGS} -Iinclude -I. -stdlib=libc++"

for file in $FUZZER_FILES; do
  fuzzer_name=$(basename $file .cc)
  echo "Building fuzzer $fuzzer_name"
  $CXX $CXXFLAGS \
    $file -o $OUT/$fuzzer_name \
    -lFuzzingEngine ${FUZZER_LIBRARIES}
done

# Copy dictionaries and options files to $OUT/
for dict in $FUZZER_DICTIONARIES; do
  cp $dict $OUT/
done

cp $SRC/grpc/tools/fuzzer/options/*.options $OUT/

# We don't have a consistent naming convention between fuzzer files and corpus
# directories so we resort to hard coding zipping corpuses
zip $OUT/fuzzer_seed_corpus.zip test/core/json/corpus/*
zip $OUT/uri_fuzzer_test_seed_corpus.zip test/core/client_channel/uri_corpus/*
zip $OUT/request_fuzzer_seed_corpus.zip test/core/http/request_corpus/*
zip $OUT/response_fuzzer_seed_corpus.zip test/core/http/response_corpus/*
zip $OUT/fuzzer_response_seed_corpus.zip test/core/nanopb/corpus_response/*
zip $OUT/fuzzer_serverlist_seed_corpus.zip test/core/nanopb/corpus_serverlist/*
zip $OUT/percent_decode_fuzzer_seed_corpus.zip test/core/slice/percent_decode_corpus/*
zip $OUT/percent_encode_fuzzer_seed_corpus.zip test/core/slice/percent_encode_corpus/*
zip $OUT/hpack_parser_fuzzer_test_seed_corpus.zip test/core/transport/chttp2/hpack_parser_corpus/*
zip $OUT/api_fuzzer_seed_corpus.zip test/core/end2end/fuzzers/api_fuzzer_corpus/*
zip $OUT/client_fuzzer_seed_corpus.zip test/core/end2end/fuzzers/client_fuzzer_corpus/*
zip $OUT/server_fuzzer_seed_corpus.zip test/core/end2end/fuzzers/server_fuzzer_corpus/*
zip $OUT/ssl_server_fuzzer_seed_corpus.zip test/core/security/corpus/ssl_server_corpus/*