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