summaryrefslogtreecommitdiffstats
path: root/Tests/Fuzzing/xml_parser_fuzzer.cc
blob: df8e17f3a61cb047dad0ba839e98afc066f42784 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
/* Distributed under the OSI-approved BSD 3-Clause License.  See accompanying
   file LICENSE.rst or https://cmake.org/licensing for details.  */

#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>

#include "cmXMLParser.h"

extern "C" int LLVMFuzzerTestOneInput(uint8_t const* 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;
}