Coverage Report

Created: 2025-11-16 07:29

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/kea-fuzzer/fuzz_agent.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 <agent/parser_context.h>
11
#include <agent/simple_parser.h>
12
#include <agent/ca_cfg_mgr.h>
13
14
#include <cc/data.h>
15
#include <exceptions/exceptions.h>
16
17
#include <string>
18
#include <memory>
19
20
using namespace isc::agent;
21
using namespace isc::data;
22
23
2.99k
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
24
2.99k
    FuzzedDataProvider fdp(data, size);
25
2.99k
    bool checkOnly = fdp.ConsumeBool();
26
27
2.99k
    AgentSimpleParser simpleParser;
28
2.99k
    CtrlAgentCfgContextPtr ctxPtr(new CtrlAgentCfgContext());
29
2.99k
    ParserContext ctx;
30
2.99k
    ElementPtr elem;
31
32
    // Generate random parsing mode
33
2.99k
    const uint8_t mode = fdp.ConsumeIntegralInRange<uint8_t>(0, 2);
34
2.99k
    ParserContext::ParserType type = ParserContext::PARSER_JSON;
35
2.99k
    if (mode == 1) {
36
663
        type = ParserContext::PARSER_AGENT;
37
2.33k
    } else if (mode == 2) {
38
758
        type = ParserContext::PARSER_SUB_AGENT;
39
758
    }
40
41
2.99k
    const std::string payload = fdp.ConsumeRemainingBytesAsString();
42
43
    // Target context parseString
44
2.99k
    try {
45
2.99k
        ctx.parseString(payload, type);
46
2.99k
    } catch (const isc::Exception&) {
47
        // Slient exceptions
48
2.76k
    }
49
50
    // Parse payload to JSON
51
2.99k
    try {
52
2.99k
        elem = Element::fromJSON(payload);
53
2.99k
    } catch (...) {
54
        // If failed to parse the payload, early exit
55
2.27k
        return 0;
56
2.27k
    }
57
58
    // Target SimpleParser
59
716
    try {
60
716
        AgentSimpleParser::setAllDefaults(elem);
61
716
        simpleParser.checkTlsSetup(elem);
62
716
        simpleParser.parse(ctxPtr, elem, checkOnly);
63
716
    } catch (const isc::Exception&) {
64
        // Slient exceptions
65
612
    }
66
67
716
    return 0;
68
716
}