Coverage Report

Created: 2025-06-22 08:03

/src/tidy_parse_file_fuzzer.c
Line
Count
Source (jump to first uncovered line)
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
0
int TidyXhtml(const uint8_t* data, size_t size, TidyBuffer* output, TidyBuffer* errbuf) {
26
0
  Bool ok;
27
28
0
  TidyDoc tdoc = tidyCreate();
29
30
0
  ok = tidyOptSetBool( tdoc, TidyXhtmlOut, yes );
31
0
  if (ok) tidySetErrorBuffer(tdoc, errbuf);
32
 
33
0
  char filename[256];
34
0
  sprintf(filename, "/tmp/libfuzzer.%d", getpid());
35
36
0
  FILE *fp = fopen(filename, "wb");
37
0
  if (!fp) {
38
0
    return 0;
39
0
  }
40
0
  fwrite(data, size, 1, fp);
41
0
  fclose(fp);
42
43
0
  tidyParseFile(tdoc, filename);
44
45
0
  tidyRelease( tdoc );
46
0
  unlink(filename);
47
48
0
  return 0;
49
0
}
50
51
88
int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
52
88
  TidyBuffer fuzz_toutput;
53
88
  TidyBuffer fuzz_terror;
54
55
88
  tidyBufInit(&fuzz_toutput);
56
88
  tidyBufInit(&fuzz_terror);
57
58
88
  TidyXhtml(data, size, &fuzz_toutput, &fuzz_terror);
59
60
88
  tidyBufFree(&fuzz_toutput);
61
88
  tidyBufFree(&fuzz_terror);
62
88
  return 0;
63
88
}
64