1#!/bin/bash -eu
2# Copyright 2017 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
18make -j$(nproc) cmake_build
19
20$CC $CFLAGS -Isrc -Ibuild/src -c $SRC/cmark/test/cmark-fuzz.c -o cmark_fuzzer.o
21$CXX $CXXFLAGS $LIB_FUZZING_ENGINE cmark_fuzzer.o build/src/libcmark.a -o $OUT/cmark_fuzzer
22
23cp $SRC/*.options $OUT/
24cp $SRC/cmark/test/fuzzing_dictionary $OUT/cmark.dict
25
26mkdir -p corpus
27cp $SRC/cmark/test/afl_test_cases/* corpus
28
29git clone --depth 1 https://github.com/michelf/mdtest.git mdtest
30find mdtest/*.mdtest -type f -name '*.text' | while read in_file
31do
32  # Genreate unique name for each input...
33  out_file=$(sha1sum "$in_file" | cut -c 1-32)
34  # ... and prepend a four-byte 'options' header
35  printf "\0\0\0\0" > "corpus/$out_file"
36  cat "$in_file" >> "corpus/$out_file"
37done
38zip -j $OUT/cmark_fuzzer_seed_corpus.zip corpus/*
39