Coverage Report

Created: 2026-04-12 08:01

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/tidy_parse_file_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 <unistd.h>
21
#include "tidybuffio.h"
22
#include "tidy.h"
23
24
25
18.4k
int TidyXhtml(const uint8_t* data, size_t size, TidyBuffer* output, TidyBuffer* errbuf) {
26
18.4k
  Bool ok;
27
28
18.4k
  TidyDoc tdoc = tidyCreate();
29
30
18.4k
  ok = tidyOptSetBool( tdoc, TidyXhtmlOut, yes );
31
18.4k
  tidySetErrorBuffer(tdoc, errbuf);
32
33
18.4k
  char filename[256];
34
18.4k
  sprintf(filename, "/tmp/libfuzzer.%d", getpid());
35
36
18.4k
  FILE *fp = fopen(filename, "wb");
37
18.4k
  if (!fp) {
38
0
    tidyRelease( tdoc );
39
0
    return 0;
40
0
  }
41
18.4k
  fwrite(data, size, 1, fp);
42
18.4k
  fclose(fp);
43
44
18.4k
  tidyParseFile(tdoc, filename);
45
18.4k
  tidyCleanAndRepair(tdoc);
46
18.4k
  tidyRunDiagnostics(tdoc);
47
18.4k
  tidyOptSetBool(tdoc, TidyForceOutput, yes);
48
18.4k
  tidySaveBuffer(tdoc, output);
49
50
18.4k
  tidyRelease( tdoc );
51
18.4k
  unlink(filename);
52
53
18.4k
  return 0;
54
18.4k
}
55
56
39.3k
int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
57
39.3k
  TidyBuffer fuzz_toutput;
58
39.3k
  TidyBuffer fuzz_terror;
59
60
39.3k
  tidyBufInit(&fuzz_toutput);
61
39.3k
  tidyBufInit(&fuzz_terror);
62
63
39.3k
  TidyXhtml(data, size, &fuzz_toutput, &fuzz_terror);
64
65
39.3k
  tidyBufFree(&fuzz_toutput);
66
39.3k
  tidyBufFree(&fuzz_terror);
67
39.3k
  return 0;
68
39.3k
}
69