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 | |
Bob Beck | 257bfaa | 2023-07-25 10:07:38 -0700 | [diff] [blame] | 5 | #include "../pki/verify_name_match.h" |
Bob Beck | bc97b7a | 2023-04-18 08:35:15 -0600 | [diff] [blame] | 6 | |
| 7 | #include <stddef.h> |
| 8 | #include <stdint.h> |
| 9 | |
| 10 | #include <fuzzer/FuzzedDataProvider.h> |
| 11 | |
| 12 | #include <vector> |
| 13 | |
Bob Beck | 257bfaa | 2023-07-25 10:07:38 -0700 | [diff] [blame] | 14 | #include "../pki/input.h" |
Bob Beck | bc97b7a | 2023-04-18 08:35:15 -0600 | [diff] [blame] | 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 | |
Bob Beck | 2e11917 | 2023-08-14 11:06:38 -0600 | [diff] [blame] | 27 | bssl::der::Input in1(first_part); |
| 28 | bssl::der::Input in2(second_part); |
Bob Beck | 257bfaa | 2023-07-25 10:07:38 -0700 | [diff] [blame] | 29 | bool match = bssl::VerifyNameInSubtree(in1, in2); |
| 30 | bool reverse_order_match = bssl::VerifyNameInSubtree(in2, in1); |
Bob Beck | bc97b7a | 2023-04-18 08:35:15 -0600 | [diff] [blame] | 31 | // If both InSubtree matches are true, then in1 == in2 (modulo normalization). |
Bob Beck | 2e11917 | 2023-08-14 11:06:38 -0600 | [diff] [blame] | 32 | if (match && reverse_order_match) { |
Bob Beck | 257bfaa | 2023-07-25 10:07:38 -0700 | [diff] [blame] | 33 | if (!bssl::VerifyNameMatch(in1, in2)) { |
Bob Beck | 2e11917 | 2023-08-14 11:06:38 -0600 | [diff] [blame] | 34 | abort(); |
| 35 | } |
| 36 | } |
Bob Beck | bc97b7a | 2023-04-18 08:35:15 -0600 | [diff] [blame] | 37 | return 0; |
| 38 | } |