Coverage Report

Created: 2025-07-18 07:11

/src/tidy_parse_string_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 "tidybuffio.h"
21
#include "tidy.h"
22
23
24
15.3k
int TidyXhtml(const char* input, TidyBuffer* output, TidyBuffer* errbuf) {
25
15.3k
  TidyDoc tdoc = tidyCreate();
26
15.3k
  tidyOptSetBool( tdoc, TidyXhtmlOut, yes );
27
15.3k
  tidySetErrorBuffer(tdoc, errbuf);
28
29
15.3k
  tidyParseString(tdoc, input);
30
31
15.3k
  tidyCleanAndRepair(tdoc);
32
15.3k
  tidyRunDiagnostics(tdoc);
33
15.3k
  tidyOptSetBool(tdoc, TidyForceOutput, yes);
34
15.3k
  tidySaveBuffer(tdoc, output);
35
15.3k
  tidyRelease( tdoc );
36
15.3k
  return 0;
37
15.3k
}
38
39
32.0k
int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
40
32.0k
  char *fuzz_inp = malloc(size+1);
41
32.0k
  memcpy(fuzz_inp, data, size);
42
32.0k
  fuzz_inp[size] = '\0';
43
44
32.0k
  TidyBuffer fuzz_toutput;
45
32.0k
  TidyBuffer fuzz_terror;
46
47
32.0k
  tidyBufInit(&fuzz_toutput);
48
32.0k
  tidyBufInit(&fuzz_terror);
49
50
32.0k
  TidyXhtml(fuzz_inp, &fuzz_toutput, &fuzz_terror);
51
52
32.0k
  tidyBufFree(&fuzz_toutput);
53
32.0k
  tidyBufFree(&fuzz_terror);
54
32.0k
  free(fuzz_inp);
55
32.0k
  return 0;
56
32.0k
}
57