Coverage Report

Created: 2025-12-08 07:54

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/kea-fuzzer/fuzz_cc.cc
Line
Count
Source
1
// Copyright (C) 2025 Ada Logcis Ltd.
2
//
3
// This Source Code Form is subject to the terms of the Mozilla Public
4
// License, v. 2.0. If a copy of the MPL was not distributed with this
5
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
6
////////////////////////////////////////////////////////////////////////////////
7
#include <config.h>
8
#include <fuzzer/FuzzedDataProvider.h>
9
10
#include <exceptions/exceptions.h>
11
#include <cc/data.h>
12
#include <cc/json_feed.h>
13
#include <cc/simple_parser.h>
14
#include <asiolink/io_address.h>
15
16
#include <string>
17
#include <vector>
18
19
using namespace isc;
20
using namespace isc::data;
21
22
2.61k
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
23
2.61k
    FuzzedDataProvider fdp(data, size);
24
25
2.61k
    ElementPtr elem;
26
27
2.61k
    std::string val1 = fdp.ConsumeRandomLengthString(8);
28
2.61k
    std::string val2 = fdp.ConsumeRandomLengthString(8);
29
2.61k
    Element::types type1 = static_cast<Element::types>(fdp.ConsumeIntegralInRange<int>(0, 8));
30
2.61k
    Element::types type2 = static_cast<Element::types>(fdp.ConsumeIntegralInRange<int>(0, 8));
31
32
2.61k
    SimpleRequiredKeywords required;
33
2.61k
    required.push_back(val1);
34
2.61k
    required.push_back(val2);
35
36
2.61k
    SimpleKeywords keywords;
37
2.61k
    keywords[val1] = type1;
38
2.61k
    keywords[val2] = type2;
39
40
2.61k
    ParamsList params;
41
2.61k
    params.push_back(val1);
42
2.61k
    params.push_back(val2);
43
44
2.61k
    const std::string payload = fdp.ConsumeRemainingBytesAsString();
45
46
    // Target JSONFeed with random data
47
2.61k
    try {
48
2.61k
        config::JSONFeed feed;
49
2.61k
        feed.initModel();
50
2.61k
        feed.postBuffer(payload.c_str(), payload.length());
51
2.61k
        feed.poll();
52
2.61k
        feed.needData();
53
2.61k
        feed.feedOk();
54
2.61k
        feed.getProcessedText();
55
2.61k
        feed.toElement();
56
2.61k
        feed.getErrorMessage();
57
2.61k
    } catch (const isc::Exception&) {
58
        // Slient exceptions
59
2.13k
    }
60
61
    // Try parse payload to Element pointer
62
2.61k
    try {
63
2.61k
        elem = Element::fromJSON(payload);
64
2.61k
    } catch (...) {
65
        // Early exit for invalid json
66
1.89k
        return 0;
67
1.89k
    }
68
69
    // Target parseIntTriplet
70
718
    try {
71
718
        SimpleParser parser;
72
718
        parser.parseIntTriplet(elem, val1);
73
718
        parser.parseIntTriplet(elem, val2);
74
718
    } catch (const isc::Exception&) {
75
        // Slient exceptions
76
352
    }
77
78
    // Target checkRequired
79
718
    try {
80
718
        SimpleParser::checkRequired(required, elem);
81
718
    } catch (const isc::Exception&) {
82
        // Slient exceptions
83
698
    }
84
85
    // Target checkKeywords
86
718
    try {
87
718
        SimpleParser::checkKeywords(keywords, elem);
88
718
    } catch (const isc::Exception&) {
89
        // Slient exceptions
90
707
    }
91
92
    // Target deriveParams
93
718
    try {
94
718
        SimpleParser::deriveParams(elem, Element::createMap(), params);
95
718
    } catch (const isc::Exception&) {
96
        // Slient exceptions
97
0
    }
98
99
718
    return 0;
100
718
}