Coverage Report

Created: 2025-07-18 06:11

/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
79
             TidyBuffer *terror) {
27
79
  TidyDoc tdoc = tidyCreate();
28
79
  tidyBufClear(toutput);
29
79
  tidyBufClear(terror);
30
79
  if (tidyOptSetBool(tdoc, TidyXmlOut, yes)) {
31
79
    tidySetCharEncoding(tdoc, "utf8");
32
79
    tidySetErrorBuffer(tdoc, terror);
33
79
    tidyOptSetInt(tdoc, TidyWrapLen, 0);
34
79
    tidyOptSetBool(tdoc, TidyXmlTags, yes);
35
79
    tidyOptSetBool(tdoc, TidyQuoteNbsp, no);
36
79
    tidyOptSetBool(tdoc, TidyNumEntities, yes);
37
79
    tidyOptSetBool(tdoc, TidyQuiet, yes);
38
79
    tidyOptSetBool(tdoc, TidyMark, no);
39
79
    tidyOptSetBool(tdoc, TidyShowWarnings, no);
40
79
    tidyParseString(tdoc, fuzz_inp);
41
79
    tidyCleanAndRepair(tdoc);
42
79
    tidyRunDiagnostics(tdoc);
43
79
    tidySaveBuffer(tdoc, toutput);
44
79
  }
45
46
79
  tidyRelease(tdoc);
47
79
}
48
49
79
int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
50
79
  char *fuzz_inp = malloc(size+1);
51
79
  memcpy(fuzz_inp, data, size);
52
79
  fuzz_inp[size] = '\0';
53
54
79
  TidyBuffer fuzz_toutput;
55
79
  TidyBuffer fuzz_terror;
56
57
79
  tidyBufInit(&fuzz_toutput);
58
79
  tidyBufInit(&fuzz_terror);
59
60
79
  TidyXml(fuzz_inp, &fuzz_toutput, &fuzz_terror);
61
62
79
  free(fuzz_inp);
63
79
  tidyBufFree(&fuzz_toutput);
64
79
  tidyBufFree(&fuzz_terror);
65
79
  return 0;
66
79
}