David Benjamin | fd06601 | 2016-11-15 00:47:17 -0500 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | # Copyright (c) 2016, Google Inc. |
| 3 | # |
| 4 | # Permission to use, copy, modify, and/or distribute this software for any |
| 5 | # purpose with or without fee is hereby granted, provided that the above |
| 6 | # copyright notice and this permission notice appear in all copies. |
| 7 | # |
| 8 | # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES |
| 9 | # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF |
| 10 | # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY |
| 11 | # SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES |
| 12 | # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION |
| 13 | # OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN |
| 14 | # CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
| 15 | |
| 16 | set -ex |
| 17 | |
| 18 | if [[ $# -ne 2 ]]; then |
| 19 | echo "Usage: $0 fuzzer_mode_build_dir no_fuzzer_mode_build_dir" |
| 20 | exit 1 |
| 21 | fi |
| 22 | |
| 23 | fuzzer_mode_build_dir=$1 |
| 24 | no_fuzzer_mode_build_dir=$2 |
| 25 | |
| 26 | |
| 27 | # Sanity-check the build directories. |
| 28 | |
| 29 | if ! grep -q '^FUZZ:' "$fuzzer_mode_build_dir/CMakeCache.txt"; then |
| 30 | echo "$fuzzer_mode_build_dir was not built with -DFUZZ=1" |
| 31 | exit 1 |
| 32 | fi |
| 33 | |
| 34 | if grep -q '^NO_FUZZER_MODE:' "$fuzzer_mode_build_dir/CMakeCache.txt"; then |
| 35 | echo "$fuzzer_mode_build_dir was built with -DNO_FUZZER_MODE=1" |
| 36 | exit 1 |
| 37 | fi |
| 38 | |
| 39 | if ! grep -q '^FUZZ:' "$no_fuzzer_mode_build_dir/CMakeCache.txt"; then |
| 40 | echo "$no_fuzzer_mode_build_dir was not built with -DFUZZ=1" |
| 41 | exit 1 |
| 42 | fi |
| 43 | |
| 44 | if ! grep -q '^NO_FUZZER_MODE:' "$no_fuzzer_mode_build_dir/CMakeCache.txt"; then |
| 45 | echo "$no_fuzzer_mode_build_dir was not built with -DNO_FUZZER_MODE=1" |
| 46 | exit 1 |
| 47 | fi |
| 48 | |
| 49 | |
| 50 | # Sanity-check the current working directory. |
| 51 | |
| 52 | assert_directory() { |
| 53 | if [[ ! -d $1 ]]; then |
| 54 | echo "$1 not found." |
| 55 | exit 1 |
| 56 | fi |
| 57 | } |
| 58 | |
| 59 | assert_directory client_corpus |
| 60 | assert_directory client_corpus_no_fuzzer_mode |
| 61 | assert_directory server_corpus |
| 62 | assert_directory server_corpus_no_fuzzer_mode |
David Benjamin | 2ff44b1 | 2017-09-06 18:41:25 -0400 | [diff] [blame] | 63 | assert_directory dtls_client_corpus |
| 64 | assert_directory dtls_server_corpus |
David Benjamin | fd06601 | 2016-11-15 00:47:17 -0500 | [diff] [blame] | 65 | |
| 66 | |
| 67 | # Gather new transcripts. Ignore errors in running the tests. |
| 68 | |
| 69 | fuzzer_mode_shim=$(readlink -f "$fuzzer_mode_build_dir/ssl/test/bssl_shim") |
| 70 | no_fuzzer_mode_shim=$(readlink -f \ |
| 71 | "$no_fuzzer_mode_build_dir/ssl/test/bssl_shim") |
| 72 | |
Matthew Braithwaite | 3d53d1f | 2020-02-04 15:55:10 -0800 | [diff] [blame] | 73 | fuzzer_mode_handshaker=$(readlink -f \ |
| 74 | "$fuzzer_mode_build_dir/ssl/test/handshaker") |
| 75 | no_fuzzer_mode_handshaker=$(readlink -f \ |
| 76 | "$no_fuzzer_mode_build_dir/ssl/test/handshaker") |
| 77 | |
Matthew Braithwaite | a2dd781 | 2018-04-05 16:48:38 -0700 | [diff] [blame] | 78 | fuzzer_mode_transcripts=$(mktemp -d '/tmp/boringssl-transcript-fuzzer-mode.XXXXXX') |
| 79 | no_fuzzer_mode_transcripts=$(mktemp -d '/tmp/boringssl-transcript-no-fuzzer-mode.XXXXXX') |
David Benjamin | fd06601 | 2016-11-15 00:47:17 -0500 | [diff] [blame] | 80 | |
| 81 | echo Recording fuzzer-mode transcripts |
| 82 | (cd ../ssl/test/runner/ && go test \ |
| 83 | -shim-path "$fuzzer_mode_shim" \ |
Matthew Braithwaite | 3d53d1f | 2020-02-04 15:55:10 -0800 | [diff] [blame] | 84 | -handshaker-path "$fuzzer_mode_handshaker" \ |
David Benjamin | fd06601 | 2016-11-15 00:47:17 -0500 | [diff] [blame] | 85 | -transcript-dir "$fuzzer_mode_transcripts" \ |
| 86 | -fuzzer \ |
| 87 | -deterministic) || true |
| 88 | |
| 89 | echo Recording non-fuzzer-mode transcripts |
| 90 | (cd ../ssl/test/runner/ && go test \ |
| 91 | -shim-path "$no_fuzzer_mode_shim" \ |
Matthew Braithwaite | 3d53d1f | 2020-02-04 15:55:10 -0800 | [diff] [blame] | 92 | -handshaker-path "$no_fuzzer_mode_handshaker" \ |
David Benjamin | fd06601 | 2016-11-15 00:47:17 -0500 | [diff] [blame] | 93 | -transcript-dir "$no_fuzzer_mode_transcripts" \ |
Matthew Braithwaite | a2dd781 | 2018-04-05 16:48:38 -0700 | [diff] [blame] | 94 | -deterministic) |
David Benjamin | fd06601 | 2016-11-15 00:47:17 -0500 | [diff] [blame] | 95 | |
| 96 | |
| 97 | # Minimize the existing corpora. |
| 98 | |
| 99 | minimize_corpus() { |
| 100 | local fuzzer="$1" |
| 101 | local corpus="$2" |
| 102 | |
| 103 | echo "Minimizing ${corpus}" |
| 104 | mv "$corpus" "${corpus}_old" |
| 105 | mkdir "$corpus" |
| 106 | "$fuzzer" -max_len=50000 -merge=1 "$corpus" "${corpus}_old" |
| 107 | rm -Rf "${corpus}_old" |
| 108 | } |
| 109 | |
| 110 | minimize_corpus "$fuzzer_mode_build_dir/fuzz/client" client_corpus |
| 111 | minimize_corpus "$fuzzer_mode_build_dir/fuzz/server" server_corpus |
| 112 | minimize_corpus "$no_fuzzer_mode_build_dir/fuzz/client" client_corpus_no_fuzzer_mode |
| 113 | minimize_corpus "$no_fuzzer_mode_build_dir/fuzz/server" server_corpus_no_fuzzer_mode |
David Benjamin | 2ff44b1 | 2017-09-06 18:41:25 -0400 | [diff] [blame] | 114 | minimize_corpus "$fuzzer_mode_build_dir/fuzz/dtls_client" dtls_client_corpus |
| 115 | minimize_corpus "$fuzzer_mode_build_dir/fuzz/dtls_server" dtls_server_corpus |
David Benjamin | 94b477c | 2021-04-14 13:32:38 -0400 | [diff] [blame] | 116 | minimize_corpus "$fuzzer_mode_build_dir/fuzz/decode_client_hello_inner" decode_client_hello_inner_corpus |
David Benjamin | fd06601 | 2016-11-15 00:47:17 -0500 | [diff] [blame] | 117 | |
| 118 | |
| 119 | # Incorporate the new transcripts. |
| 120 | |
| 121 | "$fuzzer_mode_build_dir/fuzz/client" -max_len=50000 -merge=1 client_corpus "${fuzzer_mode_transcripts}/tls/client" |
| 122 | "$fuzzer_mode_build_dir/fuzz/server" -max_len=50000 -merge=1 server_corpus "${fuzzer_mode_transcripts}/tls/server" |
| 123 | "$no_fuzzer_mode_build_dir/fuzz/client" -max_len=50000 -merge=1 client_corpus_no_fuzzer_mode "${no_fuzzer_mode_transcripts}/tls/client" |
| 124 | "$no_fuzzer_mode_build_dir/fuzz/server" -max_len=50000 -merge=1 server_corpus_no_fuzzer_mode "${no_fuzzer_mode_transcripts}/tls/server" |
David Benjamin | 2ff44b1 | 2017-09-06 18:41:25 -0400 | [diff] [blame] | 125 | "$fuzzer_mode_build_dir/fuzz/dtls_client" -max_len=50000 -merge=1 dtls_client_corpus "${fuzzer_mode_transcripts}/dtls/client" |
| 126 | "$fuzzer_mode_build_dir/fuzz/dtls_server" -max_len=50000 -merge=1 dtls_server_corpus "${fuzzer_mode_transcripts}/dtls/server" |
David Benjamin | 94b477c | 2021-04-14 13:32:38 -0400 | [diff] [blame] | 127 | "$fuzzer_mode_build_dir/fuzz/decode_client_hello_inner" -max_len=50000 -merge=1 decode_client_hello_inner_corpus "${fuzzer_mode_transcripts}/decode_client_hello_inner" |