diff options
author | AdamKorcz <adam@adalogics.com> | 2021-01-05 12:50:23 (GMT) |
---|---|---|
committer | AdamKorcz <adam@adalogics.com> | 2021-01-13 11:04:59 (GMT) |
commit | b0107165b72afe3e9b72847c350d71af347c856e (patch) | |
tree | 63a753333bdd2271f28c14d4e7d8812d39ab4da8 /Tests/Fuzzing/xml_parser_fuzzer.cc | |
parent | 764ce15ffbe232347a41e40509a2e485bae226f6 (diff) | |
download | CMake-b0107165b72afe3e9b72847c350d71af347c856e.zip CMake-b0107165b72afe3e9b72847c350d71af347c856e.tar.gz CMake-b0107165b72afe3e9b72847c350d71af347c856e.tar.bz2 |
Tests: Add a fuzzer for oss-fuzz
Diffstat (limited to 'Tests/Fuzzing/xml_parser_fuzzer.cc')
-rw-r--r-- | Tests/Fuzzing/xml_parser_fuzzer.cc | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/Tests/Fuzzing/xml_parser_fuzzer.cc b/Tests/Fuzzing/xml_parser_fuzzer.cc new file mode 100644 index 0000000..1faa918 --- /dev/null +++ b/Tests/Fuzzing/xml_parser_fuzzer.cc @@ -0,0 +1,27 @@ +/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying + file Copyright.txt or https://cmake.org/licensing for details. */ + +#include <stdint.h> +#include <stdio.h> +#include <stdlib.h> + +#include "cmXMLParser.h" + +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + char test_file[] = "libfuzzer.xml"; + + FILE* fp = fopen(test_file, "wb"); + if (!fp) + return 0; + fwrite(data, size, 1, fp); + fclose(fp); + + cmXMLParser parser; + if (!parser.ParseFile(test_file)) { + return 1; + } + + remove(test_file); + return 0; +} |