oss-fuzz/projects/expat/parse_fuzzer.cc

39 lines
957 B
C++

// 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"
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) {
for (int use_ns = 0; use_ns <= 1; ++use_ns) {
XML_Parser parser =
use_ns ? XML_ParserCreateNS(kEncoding, '\n') :
XML_ParserCreate(kEncoding);
XML_Parse(parser, reinterpret_cast<const char*>(data), size, true);
XML_ParserFree(parser);
}
return 0;
}