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