Coverage Report

Created: 2025-08-26 06:02

/src/tidy_xml_fuzzer.c
Line
Count
Source
1
/*
2
 * Copyright 2021 Google LLC
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
#include <sys/types.h>
17
#include <stdlib.h>
18
#include <stdio.h>
19
#include <stdint.h>
20
#include "tidy.h"
21
#include "tidybuffio.h"
22
#include "tidyenum.h"
23
#include "tidyplatform.h"
24
25
void TidyXml(char *fuzz_inp, TidyBuffer *toutput,
26
80
             TidyBuffer *terror) {
27
80
  TidyDoc tdoc = tidyCreate();
28
80
  tidyBufClear(toutput);
29
80
  tidyBufClear(terror);
30
80
  if (tidyOptSetBool(tdoc, TidyXmlOut, yes)) {
31
80
    tidySetCharEncoding(tdoc, "utf8");
32
80
    tidySetErrorBuffer(tdoc, terror);
33
80
    tidyOptSetInt(tdoc, TidyWrapLen, 0);
34
80
    tidyOptSetBool(tdoc, TidyXmlTags, yes);
35
80
    tidyOptSetBool(tdoc, TidyQuoteNbsp, no);
36
80
    tidyOptSetBool(tdoc, TidyNumEntities, yes);
37
80
    tidyOptSetBool(tdoc, TidyQuiet, yes);
38
80
    tidyOptSetBool(tdoc, TidyMark, no);
39
80
    tidyOptSetBool(tdoc, TidyShowWarnings, no);
40
80
    tidyParseString(tdoc, fuzz_inp);
41
80
    tidyCleanAndRepair(tdoc);
42
80
    tidyRunDiagnostics(tdoc);
43
80
    tidySaveBuffer(tdoc, toutput);
44
80
  }
45
46
80
  tidyRelease(tdoc);
47
80
}
48
49
80
int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
50
80
  char *fuzz_inp = malloc(size+1);
51
80
  memcpy(fuzz_inp, data, size);
52
80
  fuzz_inp[size] = '\0';
53
54
80
  TidyBuffer fuzz_toutput;
55
80
  TidyBuffer fuzz_terror;
56
57
80
  tidyBufInit(&fuzz_toutput);
58
80
  tidyBufInit(&fuzz_terror);
59
60
80
  TidyXml(fuzz_inp, &fuzz_toutput, &fuzz_terror);
61
62
80
  free(fuzz_inp);
63
80
  tidyBufFree(&fuzz_toutput);
64
80
  tidyBufFree(&fuzz_terror);
65
80
  return 0;
66
80
}