/src/decode_get_power_supply_status_resp_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 <stdint.h> |
18 | | #include <stddef.h> |
19 | | #include <vector> |
20 | | |
21 | | extern "C" { |
22 | | #include "base.h" |
23 | | #include "diagnostics.h" |
24 | | #include "debug-token.h" |
25 | | #include "device-capability-discovery.h" |
26 | | #include "device-configuration.h" |
27 | | #include "firmware-utils.h" |
28 | | #include "platform-environmental.h" |
29 | | #include "network-ports.h" |
30 | | #include "pci-links.h" |
31 | | } |
32 | | |
33 | | #include "fuzzer_helpers.h" |
34 | | |
35 | 5.42k | extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { |
36 | 5.42k | if (size < 2) return 0; |
37 | | |
38 | 5.37k | const uint8_t* payload = data; |
39 | 5.37k | size_t payload_len = size; |
40 | | |
41 | 5.37k | if (!validate_nsm_msg_length(payload, payload_len)) { |
42 | 150 | return 0; |
43 | 150 | } |
44 | | |
45 | 5.22k | const struct nsm_msg* msg = reinterpret_cast<const struct nsm_msg*>(payload); |
46 | 5.22k | const struct nsm_msg_hdr* hdr = reinterpret_cast<const struct nsm_msg_hdr*>(payload); |
47 | | |
48 | | // Mismatch prevention: verify request/response type |
49 | 5.22k | if (hdr->request != false) { |
50 | 440 | return 0; |
51 | 440 | } |
52 | | |
53 | 4.78k | std::vector<uint8_t> out_buf(65536, 0); |
54 | 4.78k | uint8_t fuzz_cc = 0; |
55 | 4.78k | uint16_t fuzz_reason_code = 0; |
56 | 4.78k | std::vector<uint8_t> fuzz_power_supply_status_buf(65536, 0); |
57 | 4.78k | uint8_t* fuzz_power_supply_status = reinterpret_cast<uint8_t*>(fuzz_power_supply_status_buf.data()); |
58 | 4.78k | decode_get_power_supply_status_resp(msg, payload_len, &fuzz_cc, &fuzz_reason_code, fuzz_power_supply_status); |
59 | | |
60 | 4.78k | return 0; |
61 | 5.22k | } |