• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

mendersoftware / mender / 2217914841

16 Dec 2025 02:09PM UTC coverage: 79.682% (-0.05%) from 79.734%
2217914841

push

gitlab-ci

web-flow
Merge pull request #1863 from michalkopczan/MEN-9098-out-of-bounds-check

fix: Sanitize header list of payloads and corresponding type-info files

8 of 12 new or added lines in 3 files covered. (66.67%)

33 existing lines in 1 file now uncovered.

7871 of 9878 relevant lines covered (79.68%)

13898.54 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

69.44
/src/artifact/artifact.cpp
1
// Copyright 2023 Northern.tech AS
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 <artifact/artifact.hpp>
16

17
#include <common/error.hpp>
18
#include <common/expected.hpp>
19

20
#include <artifact/error.hpp>
21

22

23
namespace mender {
24
namespace artifact {
25

26
namespace error = mender::common::error;
27
namespace expected = mender::common::expected;
28

29

30
ExpectedArtifact Parse(io::Reader &reader, config::ParserConfig conf) {
116✔
31
        return parser::Parse(reader, conf);
116✔
32
}
33

34
ExpectedPayloadHeaderView View(parser::Artifact &artifact, size_t index) {
146✔
35
        // Check if the index is available
36
        if (index >= artifact.header.info.payloads.size()) {
146✔
37
                return expected::unexpected(
×
38
                        parser_error::MakeError(parser_error::Code::ParseError, "Payload index out of range"));
×
39
        }
40

41
        if (index >= artifact.header.subHeaders.size()) {
146✔
NEW
42
                return expected::unexpected(
×
NEW
43
                        parser_error::MakeError(parser_error::Code::ParseError, "Header missing type-info"));
×
44
        }
45

46
        mender::common::json::Json meta_data;
146✔
47
        if (artifact.header.subHeaders.at(index).metadata) {
146✔
48
                meta_data = artifact.header.subHeaders.at(index).metadata.value();
60✔
49
        }
50
        return PayloadHeaderView {
146✔
51
                .version = artifact.version.version,
146✔
52
                .header =
53
                        HeaderView {
54
                                .artifact_group = artifact.header.info.provides.artifact_group.value_or(""),
55
                                .artifact_name = artifact.header.info.provides.artifact_name,
146✔
56
                                .payload_type = artifact.header.info.payloads.at(index).name,
146✔
57
                                .header_info = artifact.header.info,
146✔
58
                                .type_info = artifact.header.subHeaders.at(index).type_info,
146✔
59
                                .meta_data = meta_data,
60
                        },
61
        };
146✔
62
};
63

64
unordered_map<string, string> HeaderView::GetProvides() const {
×
65
        unordered_map<string, string> ret;
66
        ret["artifact_name"] = artifact_name;
×
67
        if (artifact_group != "") {
×
68
                ret["artifact_group"] = artifact_group;
×
69
        }
70
        if (type_info.artifact_provides) {
×
71
                ret.insert(type_info.artifact_provides->cbegin(), type_info.artifact_provides->cend());
×
72
        }
73

74
        return ret;
×
75
}
76

77
unordered_map<string, vector<string>> HeaderView::GetDepends() const {
124✔
78
        unordered_map<string, vector<string>> ret;
79
        ret["device_type"] = header_info.depends.device_type;
372✔
80
        if (header_info.depends.artifact_name) {
124✔
81
                ret["artifact_name"] = header_info.depends.artifact_name.value();
33✔
82
        }
83
        if (header_info.depends.artifact_group) {
124✔
84
                ret["artifact_group"] = header_info.depends.artifact_group.value();
33✔
85
        }
86
        if (type_info.artifact_depends) {
124✔
87
                for (const auto &kv : type_info.artifact_depends.value()) {
13✔
88
                        // type_info.artifact_depends are just <string, string> pairs, we
89
                        // need <string, vector<string>> pairs
90
                        ret[kv.first] = vector<string> {kv.second};
10✔
91
                }
92
        }
93

94
        return ret;
124✔
95
}
96

97
} // namespace artifact
98
} // namespace mender
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc