Coverage Report

Created: 2026-02-14 07:22

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
3.36k
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
23
3.36k
    FuzzedDataProvider fdp(data, size);
24
25
3.36k
    ElementPtr elem;
26
27
3.36k
    std::string val1 = fdp.ConsumeRandomLengthString(8);
28
3.36k
    std::string val2 = fdp.ConsumeRandomLengthString(8);
29
3.36k
    Element::types type1 = static_cast<Element::types>(fdp.ConsumeIntegralInRange<int>(0, 8));
30
3.36k
    Element::types type2 = static_cast<Element::types>(fdp.ConsumeIntegralInRange<int>(0, 8));
31
32
3.36k
    SimpleRequiredKeywords required;
33
3.36k
    required.push_back(val1);
34
3.36k
    required.push_back(val2);
35
36
3.36k
    SimpleKeywords keywords;
37
3.36k
    keywords[val1] = type1;
38
3.36k
    keywords[val2] = type2;
39
40
3.36k
    ParamsList params;
41
3.36k
    params.push_back(val1);
42
3.36k
    params.push_back(val2);
43
44
3.36k
    const std::string payload = fdp.ConsumeRemainingBytesAsString();
45
46
    // Target JSONFeed with random data
47
3.36k
    try {
48
3.36k
        config::JSONFeed feed;
49
3.36k
        feed.initModel();
50
3.36k
        feed.postBuffer(payload.c_str(), payload.length());
51
3.36k
        feed.poll();
52
3.36k
        feed.needData();
53
3.36k
        feed.feedOk();
54
3.36k
        feed.getProcessedText();
55
3.36k
        feed.toElement();
56
3.36k
        feed.getErrorMessage();
57
3.36k
    } catch (const isc::Exception&) {
58
        // Slient exceptions
59
2.28k
    }
60
61
    // Try parse payload to Element pointer
62
3.36k
    try {
63
3.36k
        elem = Element::fromJSON(payload);
64
3.36k
    } catch (...) {
65
        // Early exit for invalid json
66
1.94k
        return 0;
67
1.94k
    }
68
69
    // Target parseIntTriplet
70
1.42k
    try {
71
1.42k
        SimpleParser parser;
72
1.42k
        parser.parseIntTriplet(elem, val1);
73
1.42k
        parser.parseIntTriplet(elem, val2);
74
1.42k
    } catch (const isc::Exception&) {
75
        // Slient exceptions
76
707
    }
77
78
    // Target checkRequired
79
1.42k
    try {
80
1.42k
        SimpleParser::checkRequired(required, elem);
81
1.42k
    } catch (const isc::Exception&) {
82
        // Slient exceptions
83
1.08k
    }
84
85
    // Target checkKeywords
86
1.42k
    try {
87
1.42k
        SimpleParser::checkKeywords(keywords, elem);
88
1.42k
    } catch (const isc::Exception&) {
89
        // Slient exceptions
90
1.37k
    }
91
92
    // Target deriveParams
93
1.42k
    try {
94
1.42k
        SimpleParser::deriveParams(elem, Element::createMap(), params);
95
1.42k
    } catch (const isc::Exception&) {
96
        // Slient exceptions
97
0
    }
98
99
1.42k
    return 0;
100
1.42k
}