Coverage Report

Created: 2024-05-20 07:03

/src/tidy_fuzzer.c
Line
Count
Source (jump to first uncovered line)
1
// Copyright 2018 Google Inc.
2
//
3
// Licensed under the Apache License, Version 2.0 (the "License");
4
// you may not use this file except in compliance with the License.
5
// You may obtain a copy of the License at
6
//
7
//      http://www.apache.org/licenses/LICENSE-2.0
8
//
9
// Unless required by applicable law or agreed to in writing, software
10
// distributed under the License is distributed on an "AS IS" BASIS,
11
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
// See the License for the specific language governing permissions and
13
// limitations under the License.
14
15
#include <stddef.h>
16
#include <stdint.h>
17
#include <stdlib.h>
18
#include <string.h>
19
20
#include "tidy.h"
21
#include "tidybuffio.h"
22
23
void run_tidy_parser(TidyBuffer* data_buffer,
24
                     TidyBuffer* output_buffer,
25
0
                     TidyBuffer* error_buffer) {
26
0
    TidyDoc tdoc = tidyCreate();
27
0
    if (tidySetErrorBuffer(tdoc, error_buffer) < 0) {
28
0
        abort();
29
0
    }
30
0
    tidyOptSetBool(tdoc, TidyXhtmlOut, yes);
31
0
    tidyOptSetBool(tdoc, TidyForceOutput, yes);
32
33
0
    if (tidyParseBuffer(tdoc, data_buffer) >= 0 &&
34
0
            tidyCleanAndRepair(tdoc) >= 0 &&
35
0
            tidyRunDiagnostics(tdoc) >= 0) {
36
0
        tidySaveBuffer(tdoc, output_buffer);
37
0
    }
38
0
    tidyRelease(tdoc);
39
0
}
40
41
88
int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
42
88
    TidyBuffer data_buffer;
43
88
    TidyBuffer output_buffer;
44
88
    TidyBuffer error_buffer;
45
88
    tidyBufInit(&data_buffer);
46
88
    tidyBufInit(&output_buffer);
47
88
    tidyBufInit(&error_buffer);
48
49
88
    tidyBufAttach(&data_buffer, (byte*)data, size);
50
88
    run_tidy_parser(&data_buffer, &output_buffer, &error_buffer);
51
52
88
    tidyBufFree(&error_buffer);
53
88
    tidyBufFree(&output_buffer);
54
88
    tidyBufDetach(&data_buffer);
55
88
    return 0;
56
88
}