blob: 226d23d029f52a4958bb50457ad69bb5d6171ef1 [file] [log] [blame]
Bob Beckbc97b7a2023-04-18 08:35:15 -06001// 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 Beck257bfaa2023-07-25 10:07:38 -07005#include "../pki/verify_name_match.h"
Bob Beckbc97b7a2023-04-18 08:35:15 -06006
7#include <stddef.h>
8#include <stdint.h>
9
10#include <fuzzer/FuzzedDataProvider.h>
11
12#include <vector>
13
Bob Beck257bfaa2023-07-25 10:07:38 -070014#include "../pki/input.h"
Bob Beckbc97b7a2023-04-18 08:35:15 -060015
16// Entry point for LibFuzzer.
17extern "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 Beck2e119172023-08-14 11:06:38 -060027 bssl::der::Input in1(first_part);
28 bssl::der::Input in2(second_part);
Bob Beck257bfaa2023-07-25 10:07:38 -070029 bool match = bssl::VerifyNameInSubtree(in1, in2);
30 bool reverse_order_match = bssl::VerifyNameInSubtree(in2, in1);
Bob Beckbc97b7a2023-04-18 08:35:15 -060031 // If both InSubtree matches are true, then in1 == in2 (modulo normalization).
Bob Beck2e119172023-08-14 11:06:38 -060032 if (match && reverse_order_match) {
Bob Beck257bfaa2023-07-25 10:07:38 -070033 if (!bssl::VerifyNameMatch(in1, in2)) {
Bob Beck2e119172023-08-14 11:06:38 -060034 abort();
35 }
36 }
Bob Beckbc97b7a2023-04-18 08:35:15 -060037 return 0;
38}