Coverage Report

Created: 2025-07-11 07:25

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