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