Bob Beck | bc97b7a | 2023-04-18 08:35:15 -0600 | [diff] [blame^] | 1 | // Copyright 2016 The Chromium Authors |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #include "verify_name_match.h" |
| 6 | |
| 7 | #include <stddef.h> |
| 8 | #include <stdint.h> |
| 9 | |
| 10 | #include <fuzzer/FuzzedDataProvider.h> |
| 11 | |
| 12 | #include <vector> |
| 13 | |
| 14 | #include "input.h" |
| 15 | |
| 16 | // Entry point for LibFuzzer. |
| 17 | extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { |
| 18 | FuzzedDataProvider fuzzed_data(data, size); |
| 19 | |
| 20 | // Intentionally using uint16_t here to avoid empty |second_part|. |
| 21 | size_t first_part_size = fuzzed_data.ConsumeIntegral<uint16_t>(); |
| 22 | std::vector<uint8_t> first_part = |
| 23 | fuzzed_data.ConsumeBytes<uint8_t>(first_part_size); |
| 24 | std::vector<uint8_t> second_part = |
| 25 | fuzzed_data.ConsumeRemainingBytes<uint8_t>(); |
| 26 | |
| 27 | bssl::der::Input in1(first_part.data(), first_part.size()); |
| 28 | bssl::der::Input in2(second_part.data(), second_part.size()); |
| 29 | bool match = net::VerifyNameInSubtree(in1, in2); |
| 30 | bool reverse_order_match = net::VerifyNameInSubtree(in2, in1); |
| 31 | // If both InSubtree matches are true, then in1 == in2 (modulo normalization). |
| 32 | if (match && reverse_order_match) |
| 33 | CHECK(net::VerifyNameMatch(in1, in2)); |
| 34 | return 0; |
| 35 | } |