Coverage Report

Created: 2026-07-16 06:33

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/pldm_package_parser_fuzzer.cc
Line
Count
Source
1
// Copyright 2026 Google LLC
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
////////////////////////////////////////////////////////////////////////////////
16
17
#include "fw-update/package_parser.hpp"
18
#include <cstdint>
19
#include <cstddef>
20
#include <vector>
21
#include <memory>
22
23
30
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
24
30
    if (size < 1) {
25
0
        return 0;
26
0
    }
27
28
30
    std::vector<uint8_t> fwPkgHdr(data, data + size);
29
30
30
    try {
31
30
        auto parser = pldm::fw_update::parsePkgHeader(fwPkgHdr);
32
30
        if (parser) {
33
            // We use the total size of the fuzzer input as the package size.
34
            // In a real scenario, the package size is the sum of the header and the payload.
35
            // Since the fuzzer input contains both, 'size' is the correct total size.
36
0
            parser->parse(fwPkgHdr, size);
37
0
        }
38
30
    } catch (...) {
39
        // Ignore all exceptions thrown by the parser, as they represent
40
        // expected behavior when parsing invalid or malformed packages.
41
0
    }
42
43
30
    return 0;
44
30
}