diff options
author | Bhargava Shastry <bshas3@gmail.com> | 2019-11-21 15:55:06 +0100 |
---|---|---|
committer | Abhishek Arya <inferno@chromium.org> | 2019-11-21 06:55:06 -0800 |
commit | 4338c429a6733e35248978b553ec9a480afe3183 (patch) | |
tree | c626af4d08d0e38a1663ff76b68976c8167e3346 | |
parent | 2dee1feec49b78e83692a4a8e51bc7b4fbcf3b83 (diff) |
expat: Use upstream fuzzer build (retain dictionaries) (#3041)
-rw-r--r-- | projects/expat/Dockerfile | 4 | ||||
-rwxr-xr-x | projects/expat/build.sh | 46 | ||||
-rw-r--r-- | projects/expat/parse_fuzzer.cc | 47 | ||||
-rw-r--r-- | projects/expat/project.yaml | 1 |
4 files changed, 21 insertions, 77 deletions
diff --git a/projects/expat/Dockerfile b/projects/expat/Dockerfile index d3499e7e..64efafff 100644 --- a/projects/expat/Dockerfile +++ b/projects/expat/Dockerfile @@ -16,8 +16,8 @@ FROM gcr.io/oss-fuzz-base/base-builder MAINTAINER mike.aizatsky@gmail.com -RUN apt-get update && apt-get install -y make autoconf automake libtool docbook2x +RUN apt-get update && apt-get install -y make autoconf automake libtool docbook2x cmake RUN git clone --depth 1 https://github.com/libexpat/libexpat expat WORKDIR expat -COPY build.sh parse_fuzzer.* *.dict $SRC/ +COPY build.sh *.dict $SRC/ diff --git a/projects/expat/build.sh b/projects/expat/build.sh index b185038f..21c4f511 100755 --- a/projects/expat/build.sh +++ b/projects/expat/build.sh @@ -15,35 +15,25 @@ # ################################################################################ -cd expat +mkdir -p build +cd build +cmake ../expat -DEXPAT_BUILD_FUZZERS=ON -DEXPAT_OSSFUZZ_BUILD=ON -DEXPAT_SHARED_LIBS=OFF +make -j$(nproc) -./buildconf.sh -./configure -make clean -make -j$(nproc) all - -ENCODING_TYPES="UTF_16 \ - UTF_8 \ - ISO_8859_1 \ - US_ASCII \ - UTF_16BE \ - UTF_16LE" - -for encoding in $ENCODING_TYPES; do - fuzz_target_name=parse_${encoding}_fuzzer - - $CXX $CXXFLAGS -std=c++11 -Ilib/ -DENCODING_${encoding} \ - $SRC/parse_fuzzer.cc -o $OUT/${fuzz_target_name} \ - $LIB_FUZZING_ENGINE lib/.libs/libexpat.a - - # Use dictionaries in proper encoding for 16-bit encoding types. - if [[ $encoding == *"UTF_16"* ]]; then - cp $SRC/xml_${encoding}.dict $OUT/${fuzz_target_name}.dict +for fuzzer in fuzz/*; +do + cp $fuzzer $OUT + fuzzer_name=$(basename $fuzzer) + if [[ ${fuzzer_name} =~ ^.*UTF-16$ ]]; + then + cp $SRC/xml_UTF_16.dict $OUT/${fuzzer_name}.dict + elif [[ ${fuzzer_name} =~ ^.*UTF-16LE$ ]]; + then + cp $SRC/xml_UTF_16LE.dict $OUT/${fuzzer_name}.dict + elif [[ ${fuzzer_name} =~ ^.*UTF-16BE$ ]]; + then + cp $SRC/xml_UTF_16BE.dict $OUT/${fuzzer_name}.dict else - cp $SRC/xml.dict $OUT/${fuzz_target_name}.dict + cp $SRC/xml.dict $OUT/${fuzzer_name}.dict fi - - # Generate .option files for each fuzzer. - echo -en "[libfuzzer]\ndict = ${fuzz_target_name}.dict\nmax_len = 1024\n" \ - > $OUT/${fuzz_target_name}.options done diff --git a/projects/expat/parse_fuzzer.cc b/projects/expat/parse_fuzzer.cc deleted file mode 100644 index ff4cccd0..00000000 --- a/projects/expat/parse_fuzzer.cc +++ /dev/null @@ -1,47 +0,0 @@ -// Copyright 2016 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include <stddef.h> -#include <stdint.h> - -#include "expat.h" - -#include <functional> -#include <string> - -const char* kEncoding = -#if defined(ENCODING_UTF_16) -"UTF-16" -#elif defined(ENCODING_UTF_8) -"UTF-8" -#elif defined(ENCODING_ISO_8859_1) -"ISO-8859-1" -#elif defined(ENCODING_US_ASCII) -"US-ASCII" -#elif defined(ENCODING_UTF_16BE) -"UTF-16BE" -#elif defined(ENCODING_UTF_16LE) -"UTF-16LE" -#else -#error Encoding type is not specified. -#endif -; - -// Entry point for LibFuzzer. -extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { - std::string input(reinterpret_cast<const char*>(data), size); - auto hash_salt = std::hash<std::string>()(input); - - for (int use_ns = 0; use_ns <= 1; ++use_ns) { - XML_Parser parser = - use_ns ? XML_ParserCreateNS(kEncoding, '\n') : - XML_ParserCreate(kEncoding); - - // Set a hash salt to prevent MSan from crashing on random bytes generation. - XML_SetHashSalt(parser, hash_salt); - XML_Parse(parser, input.c_str(), input.size(), true); - XML_ParserFree(parser); - } - return 0; -} diff --git a/projects/expat/project.yaml b/projects/expat/project.yaml index 987a5de8..0022a91b 100644 --- a/projects/expat/project.yaml +++ b/projects/expat/project.yaml @@ -4,6 +4,7 @@ auto_ccs: - "rhodri@kynesim.co.uk" - "hanno@hboeck.de" - "webmaster@hartwork.org" + - "bshas3@gmail.com" vendor_ccs: - "cdiehl@mozilla.com" sanitizers: |